与 ngResource 相比,使用 Restangular 有什么优势? [英] What is the advantage of using Restangular over ngResource?

查看:35
本文介绍了与 ngResource 相比,使用 Restangular 有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ngResource 已经看起来很简单用...实现东西

ngResource already seems really simple to implement things with...

使用 RestangularngResource?

1.1.3 $resource 将返回承诺并且可以使用 最新 PR 提交.将来是否会向 $resource 提供支持以支持 Restangular 所做的其他动词?如果发生这种情况,Restangular 似乎会消失并变得无关紧要.

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.

推荐答案

我是 Restangular 的创建者.

I'm the creator of Restangular.

我在自述文件中创建了一个部分,其中包含与 $resource 的差异.你可以在这里查看它们https://github.com/mgonto/restangular/blob/master/README.md#differences-with-resource

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

无论如何,总而言之,除了附加功能和基于承诺的方法之外,Restangular 还可以处理您的所有 URL,因此您不必了解它们.

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.

假设你有这样的汽车:/users/123/cars/456

Suppose that you have something like this for cars : /users/123/cars/456

在 $resource 中,您必须手动构建该 URL,并且您还必须为此手动构建 $resource 对象.Restangular 通过记住"网址来帮助您解决这个问题.

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.

所以如果你在某个地方这样做

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')

希望这会有所帮助!

这篇关于与 ngResource 相比,使用 Restangular 有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆