为什么 ng-Model 值未显示更新后的值
请检查我下面的代码
JS
$scope.test='xx';
$scope.testfunc=function (a) {
alert(a);
}
HTML
<input type="radio" ng-model="test" ng-click="testfunc(test)" value="aaa"/>
当我点击收音机时,我应该收到警报消息“aaa”,但我收到消息“xx”。
谁能告诉我哪里出错了
为什么 ng-Model 值未显示更新后的值
请检查我下面的代码
JS
$scope.test='xx';
$scope.testfunc=function (a) {
alert(a);
}
HTML
<input type="radio" ng-model="test" ng-click="testfunc(test)" value="aaa"/>
当我点击收音机时,我应该收到警报消息“aaa”,但我收到消息“xx”。
谁能告诉我哪里出错了
无线电的值由模型改变。
最初收音机的值为“aaa”,然后在角度“boots”之后,rasio 的值更改为 xx,如果您使用浏览器开发工具(chrome、firefox 或 IE10 及更高版本)检查元素,您应该看见。
角度完成链接(启动)后,您的收音机是这样的
<input type="radio" ng-model="test" ng-click="testfunc(test)" value="xx"/>
你的问题是你绑定了 scope.text='xx'; 这与 value='aaa' 无关
ng-model=test 引用 $scope.test。
如果您希望它是“aaa”,则需要将其绑定到 scope.test,您将其作为参数传递给 html 中的函数。
解决方案是将其作为参数传递:
<input type="radio" ng-model="test" ng-click="testfunc('xx')" value="xx"/>
或使用 jQuery:
$scope.test = $('input:radio').val();
香草JS
$scope.test = document.querySelectorAll('input:radio');