Scenario 1: controller('c',function($scope){
$scope.test=function(){
console.log(111);//打印一次
}
$scope.test();
})
Case 2:<button ng-disabled="test()"></button>
controller('c',function($scope){
$scope.test=function(){
console.log(111);//打印两次
}
})
Why is situation 2 printed twice?
ng-disabled To pass an expression, it will be disabled when the expression is true by default. Then if you put a method, it will definitely be executed.
Is the page code in your situation 1 missing? How do you trigger this method to be executed once?