【发布时间】:2016-01-05 08:12:02
【问题描述】:
我想根据指令中是否有editable属性来启用一个按钮:
可编辑:
<table-list items="users" editable></table-list>
不可编辑:
<table-list items="users"></table-list>
我试过了:
.directive('tableList', function ($attr) {
return {
restrict: 'EA',
template: '<a ng-if="editable" class="btn btn-default" href="#">Add to group</a>' +
'<table class="table table-stripped">' +
'<thead>' +
'<tr>' +
'<th>#</th>' +
'<th>Name</th>' +
'<th>Users</th>' +
'<th>Buildings</th>' +
'<th>Created at</th>' +
'</tr>' +
'</thead>' +
'<tbody>' +
'<tr ng-repeat="item in items">' +
'<th scope="row"><input type="checkbox" value="0"></th>' +
'<td><a href="#/groups/{{item.id}}">{{item.name}}</a></td>' +
'<td>_</td>' +
'<td>_</td>' +
'<td>_</td>' +
'</tr>' +
'</tbody>' +
'</table>',
scope: {
items: "=",
editable: "="
},
但是按钮没有显示。
这样做的正确方法是什么?
【问题讨论】:
标签: javascript angularjs