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:
- $http is for universal purpose. It is an Ajax call.
- $ http用于通用目的。这是一个Ajax调用。
- $http is built into the AngularJS framework.
- $ http内置于AngularJS框架中。
- $http is good for quick retrieval.
- $ http适合快速检索。
- $http is injected directly into an AngularJS controller by the developer.
- $ 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:
$资源:
- $resource wraps $http to use in RESTful web APIs.
- $ resource包装$ http以在RESTful Web API中使用。
- $resource needs to add the module separately.
- $ resource需要单独添加模块。
- $resource is good for conditions slightly more complex than $http.
- $ resource适用于比$ http稍微复杂的条件。
- $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.
- $ 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:
- $http is for universal purpose. It is an Ajax call.
- $ http用于通用目的。这是一个Ajax调用。
- $http is built into the AngularJS framework.
- $ http内置于AngularJS框架中。
- $http is good for quick retrieval.
- $ http适合快速检索。
- $http is injected directly into an AngularJS controller by the developer.
- $ 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:
$资源:
- $resource wraps $http to use in RESTful web APIs.
- $ resource包装$ http以在RESTful Web API中使用。
- $resource needs to add the module separately.
- $ resource需要单独添加模块。
- $resource is good for conditions slightly more complex than $http.
- $ resource适用于比$ http稍微复杂的条件。
- $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.
- $ 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.
你可以在这里和这里找到更多的答案。