[英]trigger radio button when page loaded in angularjs
使用angularjs,我具有以下execute()
函數,它打印選中的radio button
的值,並且工作正常,但是即使頁面上的一個radio button
已選中,我也需要在加載頁面時執行此函數。
-在這種情況下,頁面加載后應該在控制台中打印3
-如果vm.value=null
函數不應執行
僅在選中一個單選按鈕時才需要觸發功能
vm.value="3";
vm.execute=function(value){
console.log(value);
}
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">
將此代碼添加到您的控制器中
if(!angular.equals(vm.value, null)){
vm.execute(vm.value)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.