我有休息服务:
http://localhost:3000/api/brands
当我从网络浏览器测试它时,它运行良好。
我在角度服务中使用它:
var motoAdsServices = angular.module('motoAdsServices', ['ngResource']);
motoAdsServices.factory('Brand', ['$resource', function($resource) {
return $resource('http://localhost:3000/api/:id', {}, {
query: {
method: 'GET',
params: {
id: 'brands'
},
isArray: true
}
});
}]);
调用时出现错误,因为在请求 URL 中我没有端口号:
Request URL: http://localhost/api/brands
为什么端口号被截断?角切呢?
在Angular 文档中是这样写的:
参数化的 URL 模板,其参数以 : 为前缀,如 /user/:username。如果您使用带有端口号(例如http://example.com:8080/api
)的 URL,它将受到尊重。
更新
我使用 Angular 1.0.8 版(感谢@KayakDave 的关注),但Angular 文档适用于 1.2 版。