Reputation: 1378
Why ng-Model value is not showing the updated value
Please check my code below
JS
$scope.test='xx';
$scope.testfunc=function (a) {
alert(a);
}
HTML
<input type="radio" ng-model="test" ng-click="testfunc(test)" value="aaa"/>
When i tap on radio, i should get the alert message "aaa" but i am getting message"xx" .
Can anyone tell me where i went wrong
Upvotes: 0
Views: 1075
Reputation: 6701
Your problem is that you bind the scope.text='xx'; this has nothing to do with value='aaa'
ng-model=test is referencing the $scope.test.
If you want it to be 'aaa' you need to bind it to scope.test, which you pass into the function in the html as the param.
Solution would be to pass it as a param:
<input type="radio" ng-model="test" ng-click="testfunc('xx')" value="xx"/>
or with jQuery:
$scope.test = $('input:radio').val();
Vanilla JS
$scope.test = document.querySelectorAll('input:radio');
Upvotes: 0
Reputation: 909
The value of the radio is changed by the model.
Originaly the radio has the value "aaa", then after angular "boots", the value of the rasio is changed to xx, if you inspect the element using the browser developer tools(chrome, firefox, or IE10 and up), you should see it.
your radio is like this after angular finishes linking(booting)
<input type="radio" ng-model="test" ng-click="testfunc(test)" value="xx"/>
Upvotes: 2