37
如果我有一个指令myDir
,我把它叫做内ng-repeat
像这样传递变量角度指令
<my-dir myindex="{{$index}}"></my-dir>
如何访问myindex
?当我在postLink
函数中使用attrs.myindex
时,我得到实际字符串{{$index}}
。当我检查html时,它实际上是myindex="2"
。
如果我有一个指令myDir
,我把它叫做内ng-repeat
像这样传递变量角度指令
<my-dir myindex="{{$index}}"></my-dir>
如何访问myindex
?当我在postLink
函数中使用attrs.myindex
时,我得到实际字符串{{$index}}
。当我检查html时,它实际上是myindex="2"
。
尝试
<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)
}
};
})
演示:Plunker