[英]trigger radio button when page loaded in angularjs
With angularjs I have the following execute()
function,it print the value of checked radio button
and it works fine,but I need to execute this function when page loaded just if one radio button
has checked. 使用angularjs,我具有以下
execute()
函数,它打印选中的radio button
的值,并且工作正常,但是即使页面上的一个radio button
已选中,我也需要在加载页面时执行此函数。
-in this case when page loaded it should print 3 in console -在这种情况下,页面加载后应该在控制台中打印3
-if vm.value=null
function shouldn't execute -如果
vm.value=null
函数不应执行
I need to trigger function only if one radio button has checked 仅在选中一个单选按钮时才需要触发功能
vm.value="3";
vm.execute=function(value){
console.log(value);
}
Html code HTML代码
<input type="radio" ng-change=vm.execute(1) value="1" ng-model="vm.value">
<input type="radio" ng-change=vm.execute(2) value="2" ng-model="vm.value">
<input type="radio" ng-change=vm.execute(3) value="3" ng-model="vm.value">
<input type="radio" ng-change=vm.execute(4) value="4" ng-model="vm.value">
add this code in your controller 将此代码添加到您的控制器中
if(!angular.equals(vm.value, null)){
vm.execute(vm.value)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.