2014-03-06 27 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