angular设置一个定时器

1. AngularJS某一时间段后,出现另一种情况,这里需要用到定时器timeout

2. 源码:

html>
<html>
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="angular-1.3.0.js">script>
    <title>title>
head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
    <div>{{ nowtime }}div>
    <div>等待5秒显示的文字:{{ mytext }}div>
div>

<script>
    var nowtime = function () {
        return new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString();
    };

    var app = angular.module("myApp", []);
    app.controller("myCtrl", function ($scope, $interval, $timeout) {
        $interval(function () {
            $scope.nowtime = nowtime();
        }, 1000);

        $timeout(function () {
            $scope.mytext = "Java B C";
        }, 5000);
    });
script>
body>
html>

你可能感兴趣的:(JavaScript)