本文介绍了传递变量角度指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个指令MYDIR,我把它叫做内NG-重复像这样
if i have a directive myDir and I call it within ng-repeat like so
<my-dir myindex="{{$index}}"></my-dir>
我怎么可以访问myindex?我得到实际的字符串{{$指数}}当我使用attrs.myindex postLink函数中。当我检查的HTML,它实际上说myindex =2
How can I access myindex? I get actual string {{$index}} when I use attrs.myindex within postLink function. When I inspect html, it actually says myindex="2"
任何帮助AP preciated
Any help appreciated
谢谢
--MB
Thanks--MB
推荐答案
尝试
<my-dir myindex="$index"></my-dir>
然后
app.directive('myDir', function () {
return {
restrict: 'E',
scope: {
myindex: '='
},
template:'<div>{{myindex}}</div>',
link: function(scope, element, attrs){
console.log('test', scope.myindex)
}
};
})
演示:
这篇关于传递变量角度指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!