我有休息服务:

http://localhost:3000/api/brands

当我从网络浏览器进行测试时,它运行良好。

我在有 Angular 的服务中使用它:
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 吗?

Angular doc编写:

参数化的URL模板,参数以/为前缀,如/user/:username中所示。如果您使用带有端口号的URL(例如http://example.com:8080/api),则将被尊重。

更新

我使用 Angular 版本1.0.8(感谢@KayakDave引起注意),但Angular doc适用于版本1.2。

最佳答案

它有一个冒号,因此被剥夺了,有点像:id。如果您逃脱了,那应该没问题。请尝试http://localhost\:3000/api/:id。您可能会在路线或其他地方再次遇到此问题。
万一有什么变化,有关于此行为的an issue
更新: http://localhost\\:3000/api/:id

关于rest - Angular 应用程序调用休息服务时为什么会减少端口号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19909611/

10-11 22:14
查看更多