1.语法:

$resource(url,[paramDefaults],[actions],options);

详解:

(1)url:一个参数化的url模板

(2)paramDefaults:url参数的默认值

(3)actions: 用户对于resource行为的默认设置进行扩展的自定义配置的散列,该配置将会以$http.config的格式创建。

(4)options:扩展$resourceProvider行为的自定义设置

2.五种默认行为

{
"get":{method:"get"},
"save":{method:"save"},
"query":{method:"get",isArray:true},
"remove":{method:"delete"},
"delete":{method:"delete"}
} get([params],[success],[error]); save([params],postData,[success],[error]); query([params],[success],[error]); remove([params],postData,[success],[error]); delete([params],postData,[success],[error]); $save([params],[success],[error]); $remove([params],[success],[error]);

3.demo

(function () {
angular.module("Demo", ["ngResource"])
.controller("testCtrl", ["$resource",testCtrl]);
function testCtrl($resource) {
var myResource = $resource("/url/_url", {}, {
myPost: {
method: "post",
url: "/newUrl/_newUrl",
params: { id: "4" },
interceptor: {
response: function (d) {
console.log(d);
},
responseError: function (d) {
console.log(d);//这里的是随便写的地址,所以执行了error里的函数,可打印看参数及结果
}
}
}
});
myResource.get({ id: "1" }, function (d) {
console.log(d);
}, function (d) {
console.log(d);//这里的是随便写的地址,所以执行了error里的函数,可打印看参数及结果
});
myResource.query({ content: "text" }, function (d) {
console.log(d);
}, function (d) {
console.log(d);//这里的是随便写的地址,所以执行了error里的函数,可打印看参数及结果
});
myResource.save({ text: "Hello World" }, { text: "Hello World" }, function (d) {
console.log(d);
}, function (d) {
console.log(d);//这里的是随便写的地址,所以执行了error里的函数,可打印看参数及结果
});
myResource.remove({ text: "Hello World" }, { text: "Hello World" }, function (d) {
console.log(d);
}, function (d) {
console.log(d);//这里的是随便写的地址,所以执行了error里的函数,可打印看参数及结果
});
myResource.delete({ text: "Hello World" }, { text: "Hello World" }, function (d) {
console.log(d);
}, function (d) {
console.log(d);//这里的是随便写的地址,所以执行了error里的函数,可打印看参数及结果
});
var newResource = new myResource();
newResource.$save({ id: "2" }, function (d) {
console.log(d);
}, function (d) {
console.log(d);//这里的是随便写的地址,所以执行了error里的函数,可打印看参数及结果
});
newResource.$remove({ id: "3" }, function (d) {
console.log(d);
}, function (d) {
console.log(d);//这里的是随便写的地址,所以执行了error里的函数,可打印看参数及结果
});
myResource.myPost();
};
}());

.

angular $resource 的 get请求 和 post请求的更多相关文章

  1. CORS跨域请求[简单请求与复杂请求]

    CORS即Cross Origin Resource Sharing(跨来源资源共享),通俗说就是我们所熟知的跨域请求.众所周知,在以前,跨域可以采用代理.JSONP等方式,而在Modern浏览器面前 ...

  2. Access control allow origin 简单请求和复杂请求

    原文地址:http://blog.csdn.net/wangjun5159/article/details/49096445 错误信息: XMLHttpRequest cannot load http ...

  3. ASP.NET Core应用针对静态文件请求的处理[2]: 条件请求与区间请求

    通过调用ApplicationBuilder的扩展方法UseStaticFiles注册的StaticFileMiddleware中间件帮助我们处理针对文件的请求.对于StaticFileMiddlew ...

  4. Java Web中请求转发和请求包含

    1.都是在一个请求中跨越多个Servlet 2.多个Servlet在一个请求中,他们共享request对象.就是在AServle中setAttribute()保存数据在BServlet中由getAtt ...

  5. Ajax中Get请求与Post请求的区别

    Get请求和Post请求的区别 1.使用Get请求时,参数在URL中显示,而使用Post方式,则不会显示出来 2.使用Get请求发送数据量小,Post请求发送数据量大 例子 页面的HTML代码: &l ...

  6. WebApi系列~基于单请求封装多请求的设计

    回到目录 怎么说,单请求封装多请求,这句话确实有点绕了,但还是要看清楚,想明白这到底是怎么一回事,单请求即一次请求(get,post,put,delete),封闭多请求,即在客户端发送的一个请求中可能 ...

  7. 详细解读XMLHttpRequest(一)同步请求和异步请求

    本文主要参考:MDN XMLHttpRequest 让发送一个HTTP请求变得非常容易.你只需要简单的创建一个请求对象实例,打开一个URL,然后发送这个请求.当传输完毕后,结果的HTTP状态以及返回的 ...

  8. 【读书笔记】iOS网络-同步请求,队列式异步请求,异步请求的区别

    一,同步请求的最佳实践. 1,只在后台过程中使用同步请求,除非确定访问的是本地文件资源,否则请不要在主线程上使用. 2,只有在知道返回的数据不会超出应用的内存时才使用同步请求.记住,整个响应体都会位于 ...

  9. iOS开发——网络篇——文件下载(NSMutableData、NSFileHandle、NSOutputStream)和上传、压缩和解压(三方框架ZipArchive),请求头和请求体格式,断点续传Range

    一.小文件下载 NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/resources/images/minion ...

  10. request获取请求头和请求数据

    package cn.itcast.request; import java.io.IOException; import java.io.InputStream; import java.io.Pr ...

随机推荐

  1. U盘制作安装盘后容量不能恢复的解决方案

    diskpartlist diskselect disk 0/1 --看具体U盘是0还是1clean

  2. Vue之过滤器的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Ubuntu 和 centos7 服务的启动

    Ubuntu 下: /etc/init.d/nginx  start | stop | reload Centos7下: service nginx start | stop | reload

  4. laravel知识点备忘

    1.连表查询:select * from goods left join shop on goods.shopid=shop.shopid; DB::table('goods') ->leftJ ...

  5. github 获取 token

    登录github 地址:https://github.com 点击settings 在点击Developer settings 继续 继续 描述栏随意写  复选框是token的权限 都选上吧 点击红框 ...

  6. pwnable.kr 之 passcode write up

    先看源码: #include <stdio.h> #include <stdlib.h> void login(){ int passcode1; int passcode2; ...

  7. Educational Codeforces Round 50 (Rated for Div. 2)的A、B、C三题AC代码

    A题链接:https://codeforces.com/contest/1036/problem/A A题AC代码: #include <stdio.h> #include <std ...

  8. int内部方法释义

    python基本数据类型包括:int.str.list.tuple.dict.bool.set(),一切事物都是对象,对象由类创建 1. bit_length:返回数字占用的二进制最小位数 def b ...

  9. iptables之FORWARD转发链

    注意:本机路由转发的时候,才配置FORWARD转发链! #iptables –A FORWARD –s 192.168.0.0/24 –j ACCEPT #iptables –A FORWARD –d ...

  10. JS获取所有LI中第三个<SPAN>