我想用ui-bootstrap modal制作一个可重用的指令。如何将对象传递给angularjs中的指令模板?
它除了选择
在这里工作几乎是指令:
directive('update', function() {
return {
restrict: "E",
templateUrl: "tplModal.html",
scope: {
selected:"="
},
link: function(scope, elm, attr){
scope.open = function (obj) {
scope.shouldBeOpen = true;
};
scope.close = function() {
scope.shouldBeOpen = false;
};
scope.opts = {
backdropFade: true,
dialogFade:true
};
}
}
})
和tplModal.html
<button class='btn' ng-click='open(selected)'>Update</button>
<div modal="shouldBeOpen" close="close()" options="opts">
<div class="modal-header">
<h3><i class="lead" icon="{{selected.type}}"></i> {{selected.name}}</h3>
</div>
<div class="modal-body">
<!-- stuffs here -->
</div>
<div class="modal-footer">
<button class="btn btn-warning cancel" ng-click="close()">Cancel</button>
</div>
</div>
尽管scope.opts
,没有淡化效果。
这里是整个代码: http://plnkr.co/edit/Ab4BOH?p=preview
我到底做错了什么?
后这里的代码,告诉你如何使用该指令,告诉你所期望的代码做什么,以及它做了什么。 –
我更新了问题 –
你的plunk不起作用,我得到了“Plunk not found”错误。 –