html的angular从json拿到表格

来源:互联网 发布:移动工作站推荐 知乎 编辑:程序博客网 时间:2024/06/07 05:13
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script src="angular.js"></script>    <script>        var app = angular.module("myApp",[]);        app.controller("myCtrl",function ($scope,$http) {            $http({                method:"get",                url:"myJson.json"            }).then(function success(response) {                $scope.users = response.data;            },function error() {                console.log("失败");            })        })    </script></head><body ng-app="myApp" ng-controller="myCtrl">    <center>        <table border="1" cellpadding="1" cellspacing="0">            <caption>用户信息表</caption>            <thead>                <tr>                    <th>ID</th>                    <th>用户名</th>                    <th>年龄</th>                </tr>            </thead>            <tbody>                <tr ng-repeat="user in users">                    <td>{{user.id}}</td>                    <td>{{user.name}}</td>                    <td>{{user.age}}</td>                </tr>            </tbody>        </table>    </center></body></html>
原创粉丝点击