Javascript 无法从'directive'范围获取值
我试图从Javascript 无法从'directive'范围获取值,javascript,angularjs,Javascript,Angularjs,我试图从ng repeat指令中获取值,但只有$index对我进行了操作,值作为未定义进行操作 这里怎么了 我的代码: HTML: 这个 <new-array index='$index' ng-repeat="value in values">{{value}}</new-array> {{value} 应该是 <new-array index='$index' value='value' ng-repeat="value in values">{{va
ng repeat
指令
中获取值
,但只有$index
对我进行了操作,值
作为未定义
进行操作
这里怎么了
我的代码:
HTML:
这个
<new-array index='$index' ng-repeat="value in values">{{value}}</new-array>
{{value}
应该是
<new-array index='$index' value='value' ng-repeat="value in values">{{value}}</new-array>
{{value}
在指令中,您将范围设置为
scope : {
value : "=",
index : "="
}
这样,您将创建一个不从父作用域继承的隔离作用域。因此,您必须按照“simoco”的解释将值传递到指令中
<new-array index='$index' value='value' ng-repeat="value in values">{{value}}</new-array>
scope : {
value : "=",
index : "="
}