我是 Angular JS 的新手,正在尝试创建一个自定义指令,将在下面这样使用:
<div linkedlist listcolumns="{{cashAccountsColumns}}"></div>
对应的控制器如下:
$scope.cashAccountsColumns = [
{"field": "description", "title": "Description"},
{"field": "owner", "title":"Owner"},
{"field": "currentBalance", "title":"Current Balance" }
];
而该指令代码如下:
return {
restrict : 'EA',
transclude : false,
templateUrl : 'html/linkedlist.html',
scope: {
listcolumns: "@"
},
link : function(scope, element, attrs) {
}
}
模板是:
<table class="box-table" width="100%">
<thead>
<tr>
<th scope="col" ng-repeat="column in listcolumns">
{{column.title}}
</th>
</tr>
</thead>
</table>
但这并不起作用。 我在屏幕上没有获得 column.title 的值,相反,太多的行被添加到 DOM 中:
<th ng-repeat="column in listcolumns" scope="col" class="ng-scope ng-binding"></th>