2016-01-03 47 views
1

我有一个简单的NG重复与拒绝功能的单选按钮。以下作品完美的罚款:为什么使用ng-repeat的单选按钮不起作用?

<label class="radio-inline"> 
    <input type="radio" ng-model="display_as" name="display_as" value="1">position 1 
    <input type="radio" ng-model="display_as" name="display_as" value="2">position 2 
</label> 
<pre>{{ display_as }}</pre> 

但我确实看到两个单选按钮(如预期),我可以选择两个单选按钮eitherone以下,但仍$scope.display_as不确定。

<label ng-repeat="position in user.positions" class="radio-inline"> 
    <input type="radio" ng-model="display_as" name="display_as" value="{{ $index }}">{{ position.name }} 
</label> 
<pre>{{ display_as }}</pre> 

为什么哦为什么?!有没有人能告诉我我在做什么错在我的ng-repeat

+0

对于一些神秘的,如果你使用user.display_as,它的工作原理(http://jsbin.com/yaseye/edit?html,js,output)。 Excelent @ andrei-gheorghiu,在过去,我遇到了同样的问题,我只用了ng-change。 –

回答

3

ng-repeat通过user.positions为每次迭代创建一个单独的子节点$scope。这些$scope都没有display_as属性。

您可以通过使用$parent访问ng-repeat中的父$scope。在你的情况下:$parent.display_as

相关问题