I created basic application based on angularjs
HTML:
-
You are making changes to scope outside of what angular knows about (inside a timeout).
So you should use $timeout
.. otherwise you have to use $scope.$apply()
$timeout(function() {
$scope.val = true;
}, 3000);
http://jsfiddle.net/6uKAT/21/
For timeout use $timeout
and it will call $scope.$apply()
for you.
Likewise, for ajax use $http
.
if you can't use these, then you must call $scope.$apply()
yourself:
window.setTimeout(function() {
$scope.$apply(function() {
$scope.val = true;
});
}, 3000);
讨论(0)
-
Try using: $timeout
Angular's wrapper for window.setTimeout. The fn function is wrapped
into a try/catch block and delegates any exceptions to
$exceptionHandler service.
$timeout(fn[, delay][, invokeApply]);
Updated Fiddle
JavaScript
var app = angular.module('miniapp', []);
function Ctrl($scope, $timeout) {
$scope.val = false;
$timeout(function(){$scope.val = true}, 3000);
}
讨论(0)