采用NG-模型NG重复 [英] using ng-model in ng-repeat
本文介绍了采用NG-模型NG重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建角指令与模板:
<div class="directiveclass">
<div ng-repeat="i in items">
<input type="radio" ng-model="myvalue" value="{{$index}}">
</div>
</div>
在NG-模式myvalue的是指导当地范围的一部分:
The ng-model "myvalue" is part of the directive local scope:
.directive('mydirective', function()
{
return {
templateUrl: "path",
scope: {},
link : function(scope, el, attr)
{
scope.myvalue = 0;
scope.$watch('myvalue', function()
{
console.log('myvalue changed');
});
}
};
}
我点击单选按钮元素,但myvalue的值永远不会改变。
I'm clicking on the the radio buttons elements, but "myvalue" value never change.
任何想法?
样code: http://jsfiddle.net/r5jGL/
推荐答案
我找到了解决办法。
由于NG-重复创建新的范围,我已经改变了NG-模型值的 $ parent.myval ,以访问指令范围。
I found the solution. Since ng-repeat create new scope, I've changed the ng-model value to $parent.myval in order to access the directive scope.
这篇关于采用NG-模型NG重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文