AngularJs练习Demo19 Resource

 @{
Layout = null;
} <!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Resource</title>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular-resource.min.js"></script>
<script type="text/javascript">
var m1 = angular.module("myApp", ["ngResource"]);
m1.controller("firstController", ["$scope", "$resource", function ($scope, $resource) {
var data = $resource(":name", { id: '@@id' }); //name 会被替换掉,传参用@符号
//也可以这样写 var data = $resource(":name",{name:getData});//第二个参数就是用来传参
// var data = $resource(":name",{id,@@id},
//{getAge:{method:"get",params:{age:'20'},isArray:false},
//getSex:{method:"get",params:{sex:'男'},isArray:false}
//});//第三个参数就是用来自定义方法的isArray为true表示是query如果是false表示是get,第三个参数可以自定义多个方法 //支持的方法
/*
{
"get":{method:"get"},
"save":{method:"post"},
"query":{method:"get",isArray:true},
"remove":{method:"delete"},
"delete":{method:"delete"}
}
*/ $scope.data = data.get({ "name": "getData" }, { id: 20 }, function (data) {//Get请求并传参 ,GET只能取一条数据 }); $scope.data1 = data.query({ "name": "getDataList" }, function (data) {//查询多条就得用query }); //第三种方法
// $scope.data2 = data.getAge({ id: 21 }); console.log(data); //使用GET请求去请求数据
// console.log(obj);
// var objRe = $resource("", {}); }]);
</script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
{{data.name}}
{{data.age}} <ul>
<li ng-repeat="d in data1">
{{d.name}}-{{d.age}} </li>
</ul>
</div>
</div>
</body>
</html>
上一篇:HDU 4771


下一篇:VMware5.5-虚拟机的迁移和资源分配