【发布时间】:2017-02-17 15:32:51
【问题描述】:
我有一个现有的指令,我不想碰它,它是这样使用的:
<div other-directive value="xyz"></div>
问题是,指令需要很多参数,我不想每次都写。所以我的想法是添加一个进一步的指令,预先设置这些参数。
<div my-directive other-directive></div>
我的覆盖机制如下所示:
angular.module('myApp')
.directive("otherDirective", function(){
return {
restrict: "EA",
template: '<i>{{value}}</i>',
scope: {
value: "=value"
}
};
})
// overwrite "value" parameter
.directive("myDirective", function(){
return {
priority: 1000,
restrict: "A",
link: function(scope, element, attributes) {
attributes.value = "Hello";
attributes.$set('value', 'Hello');
}
};
});
第二个指令似乎无法更改第一个指令的参数。 请看我的 Plunker:http://plnkr.co/edit/HutmraGNm9U1RKl5OD2S?p=preview
【问题讨论】:
标签: angularjs angularjs-directive