![](/img/trans.png)
[英]How to stop angular from passing attributes to replaced element in custom directive
[英]Passing a custom filter with attributes to a custom directive in angular
有没有一种方法可以将自定义过滤器作为属性传递到自定义指令中? 所以如果我有指令
<my-element value="1234" filter="my-filter:attr1:attr2"><my-element>
如
angular.module("directives", ["filter"]).directive("myElement", function() {
return {
restrict: "E",
replace : true,
scope : {
value : "@",
filter : "@"
},
template: function (el, attr) {
return "<p>{{value | filter}}</p>";
},
link: function($scope){ /* linking stuff */ }
};
});
使用过滤器:
angular.module("filter", []).filter("myFilter", function() {
return function(value, attr1, attr2) {
return "filtered value";
};
};
});
自动取款机什么也没发生,我不知道这里出了什么问题...
您是否将这两个模块注入到您的应用程序模块中? 像这样:
angular.module("app", ["filter","directives"])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.