服務http/timeout案例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>服務http/timeout/interval案例</title>
    <script src="AngularJS/angular.js"></script>
    <script type="text/javascript">
        var app = angular.module("myApp",[]);
        app.controller("myCtrl",function ($scope,$http,$timeout,$interval) {
            $scope.title = "";
            $http({
                methed:"get",
                url:"myJson.json"
            }).then(function success(respons) {
                $scope.users = respons.data;
            },function error() {
                console.log("失敗")
            });
            //timeout
            $timeout(function () {
                $scope.title = "title";
            },3000);
            //$interval
            $scope.date = new Date().toLocaleTimeString();
            $interval(function () {
                $scope.date = new Date().toLocaleTimeString();
            },1000);
        });
    </script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
    <table border="1 solide blue">
        <caption>用戶信息表</caption>
        <tr>
            <th>ID</th>
            <th>name</th>
            <th>age</th>
        </tr>
        <tr ng-repeat="i in users">
            <td>{{i.id}}</td>
            <td>{{i.name}}</td>
            <td>{{i.age}}</td>
        </tr>
    </table>
    <!--timeout-->
    3秒後顯示:{{title}}<br>
    實現系統時間:{{date}}
</body>
</html>
發佈了38 篇原創文章 · 獲贊 23 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章