AngularJS中的$http服务请求数据

来源:互联网 发布:虚拟机mac os x 10.10 编辑:程序博客网 时间:2024/05/16 17:51
 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="../AngularJS/angular.js" ></script> <script> var app = angular.module("myApp",[]); app.controller("myCtrl",function($scope,$http){ //$scope.users;   $http({ method:"get", url:"myJson.json" }).then(function success(response){ //console.log(response.data[0].name); $scope.users = response.data; //console.log(users); },function error(){ console.log("失败"); }); }); </script> </head> <body ng-app="myApp" ng-controller="myCtrl"> <center> <table border="1px" cellpadding="10" 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> 
原创粉丝点击