I am a newbie in angularjs. I encountered such a problem in the project today
I want to hide p after 1S, but it has no effect.
Please tell me why there is no response
<p ng-show="on">111</p>
app.controller('myinfoCtrl', ['$scope'],function($scope) {
$scope.on=true;
setTimeout(function(){
console.log($scope.on)
$scope.on=false;
console.log($scope.on)
},1000)
}
You need to manually call $scope.$apply();
in the callback functionOr use $timeout
http://www.cnblogs.com/ys-ys/...
Hope to adopt it, thank you
Use $timeout:
Changing the variables bound in $scope directly in setTimeout will not trigger the dirty data check of the variables. Variable changes will not be synchronized to the interface, so the interface will not make changes.
I have never used setTimeout, but changing setTimeout to $timeout can achieve the effect you mentioned
<p ng-show="on">111</p>
app.controller('myinfoCtrl', ['$scope'],function($scope) {
}
Using setTimeout will not trigger the $digest loop. It is recommended to use the $timeout packaged in angular
@ Meteor Stay Why does it report an error?