我有休息服务:
http://localhost:3000/api/brands
Run Code Online (Sandbox Code Playgroud)
当我从网络浏览器测试它时效果很好.
我在角度服务中使用它:
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
}
});
}]);
Run Code Online (Sandbox Code Playgroud)
当它被调用时我有错误,因为在reqest URL中我没有端口号:
Request URL: http://localhost/api/brands
Run Code Online (Sandbox Code Playgroud)
为什么端口数字被削减?角切呢?
在Angular doc中写道:
参数化的URL模板,其参数前缀为:in/user /:username.如果您使用的是带有端口号的URL(例如http://example.com:8080/api),则会受到尊重.
UPDATE
我使用角度版本1.0.8(感谢@KayakDave供你注意),但Angular doc适用于版本1.2.