Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
150
rated 0 times [  152] [ 2]  / answers: 1 / hits: 110182  / 8 Years ago, mon, february 22, 2016, 12:00:00

I am using below code, In laravel blade



<div ng-show=displayErrorMsg class=form-group m-b alert alert-danger>{{errorMsg}}


In angularjs controller



$scope.errorMsg = Data Empty;
$scope.displayErrorMsg = true;
setTimeout(function() { $scope.displayErrorMsg = false;}, 2000);


Message not disappear after 2 second automatically as given.



But when I simply put alert(test); or click anywhere message disappears.
How to resolve this problem ?


More From » angularjs

 Answers
64

Just inject $timeout in your controller and use this.



$timeout(function() { $scope.displayErrorMsg = false;}, 2000);


Also you can use $digest or $apply as below



setTimeout(function() {
$scope.displayErrorMsg = false;
$scope.$digest();
}, 2000);

setTimeout(function () {
$scope.$apply(function(){
$scope.displayErrorMsg = false;
});
}, 2000);


Check here how these works,



http://www.sitepoint.com/understanding-angulars-apply-digest/


[#63224] Friday, February 19, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominics

Total Points: 424
Total Questions: 99
Total Answers: 107

Location: South Korea
Member since Fri, Sep 11, 2020
4 Years ago
dominics questions
Wed, Apr 6, 22, 00:00, 2 Years ago
Thu, Jan 13, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
;