0
我試圖使用角度指令與表,但我沒有看到任何數據,當我使用列表 我可以看到數據,它的工作正常。 我使用bootstrap來設計桌子樣式。 我真的不知道我做錯了什麼,角度指令與表
希望能對你有所幫助,這裏是我的代碼的主要部分:
main.html中:
<table class="table">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody ng-repeat="m in users">
<my-dir my-obj="m"></my-dir>
</tbody>
</table>
app.js :
var myApp = angular.module('myApp', ['ngRoute'])
myApp.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'pages/main.html',
controller: 'AppCtrl'
})
});
myApp.controller('AppCtrl', function($scope) {
$scope.users = [{name: 'john', age: 16}, {name: 'dani', age: 10}];
});
myApp.directive('myDir', function(){
return{
templateUrl: 'directive/mytbl.html',
replace: false,
scope:{
myObj: '='
}
}
})
mytbl.html:
<td>{{ myObj.name }}</td>
<td>{{ myObj.age }}</td>
它仍然沒有顯示數據.. – zb22
現在嘗試,錯過了在那裏的範圍。這應該工作。 – Brian
現在有用,謝謝! 我不知道有可能把這個指令放在元素內, 實際上發生了什麼事情? – zb22