$ http和$ resource有什么区别?

时间:2022-06-17 22:26:08

Can I use either for a REST call ? Or is there some minor difference ? I have used both of them in my projects with no side effects,

我可以用于REST呼叫吗?还是有一些细微的差别?我在我的项目中使用了它们,没有任何副作用,

1 个解决方案

#1


5  

These are the main differences between $http and $resource:

这些是$ http和$ resource之间的主要区别:

$http:

$ HTTP:

  1. $http is for universal purpose. It is an Ajax call.
  2. $ http用于通用目的。这是一个Ajax调用。
  3. $http is built into the AngularJS framework.
  4. $ http内置于AngularJS框架中。
  5. $http is good for quick retrieval.
  6. $ http适合快速检索。
  7. $http is injected directly into an AngularJS controller by the developer.
  8. $ http由开发人员直接注入AngularJS控制器。

For more details about $http refer: https://docs.angularjs.org/api/ng/service/$http

有关$ http的更多详细信息,请参阅:https://docs.angularjs.org/api/ng/service/$http

$resource:

$资源:

  1. $resource wraps $http to use in RESTful web APIs.
  2. $ resource包装$ http以在RESTful Web API中使用。
  3. $resource needs to add the module separately.
  4. $ resource需要单独添加模块。
  5. $resource is good for conditions slightly more complex than $http.
  6. $ resource适用于比$ http稍微复杂的条件。
  7. $resource does not allow us to do much with data once it is consumed in the application. It is in the final state when it is delivered to the HTML DOM. The data are the same that the $http method will receive.
  8. $ resource不允许我们在应用程序中使用数据后对数据做很多事情。它被传递到HTML DOM时处于最终状态。数据与$ http方法将接收的数据相同。

For more details about $resource refer: https://docs.angularjs.org/api/ngResource/service/$resource

有关$ resource的更多详细信息,请参阅:https://docs.angularjs.org/api/ngResource/service/$resource

You can find more answer here and here.

你可以在这里和这里找到更多的答案。

#1


5  

These are the main differences between $http and $resource:

这些是$ http和$ resource之间的主要区别:

$http:

$ HTTP:

  1. $http is for universal purpose. It is an Ajax call.
  2. $ http用于通用目的。这是一个Ajax调用。
  3. $http is built into the AngularJS framework.
  4. $ http内置于AngularJS框架中。
  5. $http is good for quick retrieval.
  6. $ http适合快速检索。
  7. $http is injected directly into an AngularJS controller by the developer.
  8. $ http由开发人员直接注入AngularJS控制器。

For more details about $http refer: https://docs.angularjs.org/api/ng/service/$http

有关$ http的更多详细信息,请参阅:https://docs.angularjs.org/api/ng/service/$http

$resource:

$资源:

  1. $resource wraps $http to use in RESTful web APIs.
  2. $ resource包装$ http以在RESTful Web API中使用。
  3. $resource needs to add the module separately.
  4. $ resource需要单独添加模块。
  5. $resource is good for conditions slightly more complex than $http.
  6. $ resource适用于比$ http稍微复杂的条件。
  7. $resource does not allow us to do much with data once it is consumed in the application. It is in the final state when it is delivered to the HTML DOM. The data are the same that the $http method will receive.
  8. $ resource不允许我们在应用程序中使用数据后对数据做很多事情。它被传递到HTML DOM时处于最终状态。数据与$ http方法将接收的数据相同。

For more details about $resource refer: https://docs.angularjs.org/api/ngResource/service/$resource

有关$ resource的更多详细信息,请参阅:https://docs.angularjs.org/api/ngResource/service/$resource

You can find more answer here and here.

你可以在这里和这里找到更多的答案。