ngResource
already seems really simple to implement things with...
ngResource似乎已经很容易实现了……
What are the Advantages / Disadvantages of using Restangular over ngResource?
使用restangle而不是ngResource的优点和缺点是什么?
1.1.3 $resource
will return promises and can be implimented using latest PR commit. Will future support be offered to $resource
to support additional verbs that Restangular does? And if that happens Restangular seems like it will disappear and become irrelivant.
1.1.3 $resource将返回承诺,并可以使用最新的公共关系提交来实现。$resource会提供未来的支持来支持restangle所做的其他动词吗?如果发生这种情况,它就会消失,变得毫无意义。
4 个解决方案
#1
231
I'm the creator of Restangular.
我是restangle的创建者。
I've created a section on the README with the differences against $resource. You can check them out here https://github.com/mgonto/restangular/blob/master/README.md#differences-with-resource
我在README上创建了一个与$resource不同的部分。您可以在这里查看https://github.com/mgonto/restangular/blob/master/README.md#difference -with-resource
Anyway, as a sum up, besides the additional features and the promise based approach, the idea is that Restangular can also handle all of your URLs, so that you don't have to know anything about them.
总之,总的来说,除了附加的特性和基于承诺的方法外,restangle还可以处理所有的url,这样您就不需要了解它们了。
Suppose that you have something like this for cars : /users/123/cars/456
假设你有这样的车:/用户/123/cars/456。
In $resource, You'd have to construct that URL manually and you'd also have to construct the $resource object for this manually. Restangular helps you in this by "remembering" the URLs.
在$resource中,您必须手工构造URL,并且您还必须手工构造$resource对象。restangle帮助您“记住”url。
So if you do in some place
如果在某个地方
Restangular.one("users", 123).get().then(function(user) {
$scope.user = user;
});
// Some other code
//Automatically does the request to /users/123/cars as it remembers in which object you're asking it.
$scope.user.getList('cars')
Hope this helps!
希望这可以帮助!
#2
8
I found Restangular's RequestInterceptor quite handy to remove some fields from the object before making the Request. Most REST webservices i am currently working with don't expect the id in the object data in a PUT request for example, just in the url. Generally they don't expect extra data fields that can not be updated by PUT (like the id, or a slug which is generated by setting the title etc). I found this to be straightforward with Restangular while i haven't figured out how to do it with $resource in a clean way, but i am sure its possible somehow.
我发现restangle的RequestInterceptor非常方便,可以在发出请求之前从对象中删除一些字段。我目前使用的大多数REST webservices都不希望对象数据中的id出现在PUT请求中,比如url中。一般来说,他们并不期望额外的数据字段不能通过PUT(比如id,或者通过设置标题生成的slug)来更新。我发现用restangle处理这个问题很简单,但我还没有找到如何用$resource以一种干净的方式处理这个问题的方法,但我确信这是可能的。
Obviously one could also change the webservice to just ignore those extra fields, but thats not always possible.
显然,我们也可以改变webservice,忽略那些额外的字段,但这并不总是可能的。
#3
2
ngResource does not return promises in the latest stable release (currently 1.0.6). Additionally, it looks like Restangular exposes more verbs than ngResource (it exposes PUT, OPTIONS, PATCH, etc).
在最新的稳定版本(目前为1.0.6)中,ngResource没有返回承诺。此外,看起来restangle公开的动词多于ngResource(它公开PUT、选项、补丁等)。
If you don't need the additional verbs and are on the unstable branch of AngularJS (which includes promises for ngResource), I don't see any major reason to use Restangular over ngResource.
如果您不需要额外的动词,并且在AngularJS不稳定的分支上(包括对ngResource的保证),我认为没有任何主要的理由使用restover ngResource。
Use whatever you feel comfortable with.
用你觉得舒服的东西。
#4
1
As a following up to the above answers and for new readers, like me, interested in those thoughts :
作为对以上答案的补充,对于像我这样的新读者,我对这些想法很感兴趣:
"And if that happens Restangular seems like it will disappear and become irrelivant."
“如果发生这种情况,它就会消失,变得毫无意义。”
"What happens in three months when this guy drops support for Restangular because Google's ngResource caught up to all the features it was missing."
“三个月后,当这个家伙不再支持restangle时,会发生什么呢?因为谷歌的ngResource赶上了它所缺少的所有功能。”
- [ asked 2 years ago ]
- [2年前问过]
In my opinion the only guarantee to the survive of an open-source library is the community built around it. a best example would be mariaDB and WebScaleSQL which both of them were born as a growing fork to the great relational database management system MySQL.
在我看来,开源图书馆生存的唯一保证就是围绕它建立的社区。最好的例子是mariaDB和WebScaleSQL,它们都是作为一个成长中的分支诞生于伟大的关系数据库管理系统MySQL。
At this writing time Restangular having 6699 stars and 727 forks
is now moving forward to Restangular 2.0 which is meant to support angularJs 2.0 and ES6.
在撰写此文时,拥有6699颗恒星和727台福克斯的restangle 2.0正在向前发展,它将支持angularJs 2.0和ES6。
- discussion about : https://github.com/mgonto/restangular/issues/890.
- 讨论:https://github.com/mgonto/restangular/issues/890。
- first repo preview : https://github.com/mgonto/restangular/tree/2.0-wip
- 第一个repo预览:https://github.com/mgonto/restangular/tree/2.0-wip
- ng-europe conference presented by mgonto : https://youtu.be/fWar75R1NGo
- mgonto提出的ng-europe会议:https://youtu.be/fWar75R1NGo。
#1
231
I'm the creator of Restangular.
我是restangle的创建者。
I've created a section on the README with the differences against $resource. You can check them out here https://github.com/mgonto/restangular/blob/master/README.md#differences-with-resource
我在README上创建了一个与$resource不同的部分。您可以在这里查看https://github.com/mgonto/restangular/blob/master/README.md#difference -with-resource
Anyway, as a sum up, besides the additional features and the promise based approach, the idea is that Restangular can also handle all of your URLs, so that you don't have to know anything about them.
总之,总的来说,除了附加的特性和基于承诺的方法外,restangle还可以处理所有的url,这样您就不需要了解它们了。
Suppose that you have something like this for cars : /users/123/cars/456
假设你有这样的车:/用户/123/cars/456。
In $resource, You'd have to construct that URL manually and you'd also have to construct the $resource object for this manually. Restangular helps you in this by "remembering" the URLs.
在$resource中,您必须手工构造URL,并且您还必须手工构造$resource对象。restangle帮助您“记住”url。
So if you do in some place
如果在某个地方
Restangular.one("users", 123).get().then(function(user) {
$scope.user = user;
});
// Some other code
//Automatically does the request to /users/123/cars as it remembers in which object you're asking it.
$scope.user.getList('cars')
Hope this helps!
希望这可以帮助!
#2
8
I found Restangular's RequestInterceptor quite handy to remove some fields from the object before making the Request. Most REST webservices i am currently working with don't expect the id in the object data in a PUT request for example, just in the url. Generally they don't expect extra data fields that can not be updated by PUT (like the id, or a slug which is generated by setting the title etc). I found this to be straightforward with Restangular while i haven't figured out how to do it with $resource in a clean way, but i am sure its possible somehow.
我发现restangle的RequestInterceptor非常方便,可以在发出请求之前从对象中删除一些字段。我目前使用的大多数REST webservices都不希望对象数据中的id出现在PUT请求中,比如url中。一般来说,他们并不期望额外的数据字段不能通过PUT(比如id,或者通过设置标题生成的slug)来更新。我发现用restangle处理这个问题很简单,但我还没有找到如何用$resource以一种干净的方式处理这个问题的方法,但我确信这是可能的。
Obviously one could also change the webservice to just ignore those extra fields, but thats not always possible.
显然,我们也可以改变webservice,忽略那些额外的字段,但这并不总是可能的。
#3
2
ngResource does not return promises in the latest stable release (currently 1.0.6). Additionally, it looks like Restangular exposes more verbs than ngResource (it exposes PUT, OPTIONS, PATCH, etc).
在最新的稳定版本(目前为1.0.6)中,ngResource没有返回承诺。此外,看起来restangle公开的动词多于ngResource(它公开PUT、选项、补丁等)。
If you don't need the additional verbs and are on the unstable branch of AngularJS (which includes promises for ngResource), I don't see any major reason to use Restangular over ngResource.
如果您不需要额外的动词,并且在AngularJS不稳定的分支上(包括对ngResource的保证),我认为没有任何主要的理由使用restover ngResource。
Use whatever you feel comfortable with.
用你觉得舒服的东西。
#4
1
As a following up to the above answers and for new readers, like me, interested in those thoughts :
作为对以上答案的补充,对于像我这样的新读者,我对这些想法很感兴趣:
"And if that happens Restangular seems like it will disappear and become irrelivant."
“如果发生这种情况,它就会消失,变得毫无意义。”
"What happens in three months when this guy drops support for Restangular because Google's ngResource caught up to all the features it was missing."
“三个月后,当这个家伙不再支持restangle时,会发生什么呢?因为谷歌的ngResource赶上了它所缺少的所有功能。”
- [ asked 2 years ago ]
- [2年前问过]
In my opinion the only guarantee to the survive of an open-source library is the community built around it. a best example would be mariaDB and WebScaleSQL which both of them were born as a growing fork to the great relational database management system MySQL.
在我看来,开源图书馆生存的唯一保证就是围绕它建立的社区。最好的例子是mariaDB和WebScaleSQL,它们都是作为一个成长中的分支诞生于伟大的关系数据库管理系统MySQL。
At this writing time Restangular having 6699 stars and 727 forks
is now moving forward to Restangular 2.0 which is meant to support angularJs 2.0 and ES6.
在撰写此文时,拥有6699颗恒星和727台福克斯的restangle 2.0正在向前发展,它将支持angularJs 2.0和ES6。
- discussion about : https://github.com/mgonto/restangular/issues/890.
- 讨论:https://github.com/mgonto/restangular/issues/890。
- first repo preview : https://github.com/mgonto/restangular/tree/2.0-wip
- 第一个repo预览:https://github.com/mgonto/restangular/tree/2.0-wip
- ng-europe conference presented by mgonto : https://youtu.be/fWar75R1NGo
- mgonto提出的ng-europe会议:https://youtu.be/fWar75R1NGo。