说明:AngularJS某一时间段后,出现另一种情况,这里需要用到定时器timeout
$timeout 服务, AngularJS $timeout 服务对应了 JS window.setTimeout 函数。
<!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>
输出结果:
111
222
原文链接:https://www.f2er.com/angularjs/146615.html