我有休息服务:
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 doc编写:
参数化的URL模板,参数以/为前缀,如/ user /:username中所示。如果您使用带有端口号的URL(例如http://example.com:8080/api
),则将受到尊重。
更新
它有一个冒号,因此被剥夺了,有点像:id。如果您逃脱了,那应该没问题。试试吧http://localhost\:3000/api/:id
。您可能会在路线或其他地方再次遇到此问题。万一发生变化,此行为会有一个问题。
更新: http://localhost\\:3000/api/:id
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句