读取服务器json数据,get方式
代码语言:javascript复制 <body>
<div ng-app="Home">
<div ng-controller="httpTest">
展示http服务
<p ng-repeat="name in names">{{name.name}}</p>
</div>
</div>
</body>
<script type="text/javascript">
//实例化应用对象,参数:模块名,空数组
var app=angular.module("Home",[]);
//测试$http
app.controller("httpTest",function($scope,$http){
$http.get("api.php").then(function(res){
console.log(res);
var names=res.data.list;
$scope.names=names;
});
});
</script>