Pergunta

Here is my radio buttons code

<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/>

Now when a user choose any of them then below radio button should be checked as default

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

The js code is as follow:

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

The problem is that when I choose any phone then the Inter is checked automatically but later on the value is undefined, It goes to setChoiceType but after that choice.International is undefined. If I manually choose Inter (by clicking on it) it is fine.

Foi útil?

Solução

Your radio buttons are bound to properties of the choice object. But, setPhoneType and setChoiceType update values directly on the scope - not the choice object. Also, I think you want to use value, not ng-value.

Here is plnkr.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top