1、问题背景
AngularJS某一时间段后,出现另一种情况,这里需要用到定时器timeout
2、实现源码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AngularJS之定时器(timeout)</title>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script>
var app = angular.module("timeApp",[]);
app.controller("timeController",function($scope,$timeout){
$scope.information = 111;
$timeout(function(){
$scope.information = 222;
},2000);
});
</script>
</head>
<body>
<div ng-app="timeApp" ng-controller="timeController">
<label>{{information}}</label>
</div>
</body>
</html>
3、实现结果
(1)初始化时
111
(2)2S之后
222