2014-03-06 23 views
0

这里是我的单选按钮的代码Angularjs:检查单选框自动

<input type="radio" ng-model="choice.phone" ng-value="1" name="phone" ng- 
click="setPhoneType('cell')"> cell phone<br/> 

<input type="radio" ng-model="choice.phone" ng-value="2" name="phone" ng- 
click="setPhoneType('Home')"> Home phone <br/> 

现在,当用户选择其中的任何然后在下面的单选按钮应作为托运默认

<input type="radio" ng-model="choice.International" ng-value="1" 
name="international" ng-click="setChoiceType('Inter')" ng-checked="choice.phone"> International call 

JS代码是如下:

setPhoneType = function setPhoneType(phoneType) { 
        $scope.phone = phoneType; 
        $scope.setChoiceType('Inter'); 
        return; 
}, 
setChoiceType = function setChoiceType(callType) { 
        $scope.international = callType; 
        return; 
       }, 

的问题是,当我选择任何phone那么Inter被自动检查,但后来的值是未定义的,它会去setChoiceType,但之后choice.International是未定义的。如果我手动选择Inter (by clicking on it)这很好。

+0

一个小提琴或plunkr会使它更容易帮助。 – dnc253

回答

0

您的单选按钮被绑定到选择对象的属性。但是,setPhoneType和setChoiceType更新值直接在作用域上 - 而不是选择对象。另外,我认为你想使用价值,而不是ng值。

Here is plnkr

+0

非常感谢它现在的作品:) – Sara