AngularJS中的$http服务请求数据

  <!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>
 
展开阅读全文

没有更多推荐了,返回首页