angular服务——$http

来源:互联网 发布:2016赛季林书豪数据 编辑:程序博客网 时间:2024/06/05 21:55
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>$http</title>
<script type="text/javascript" src="js/angular.min.js" ></script>
<script>
var app=angular.module("myApp",[]);
app.controller("myCtrl",function($scope,$http){
$http({
method:"get",//请求路径
url:"myJson.json"//请求的json串   自己写的json串
}).then(function zhengque(response){
//请求正确
$scope.student=response.data;

},function cuowu(){
//请求错误
alert("错误");
});
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<ul>
<li ng-repeat="s in student">姓名:{{s.name}}</li>
</ul>

</body>
</html>
原创粉丝点击