【问题标题】:How to specify url for $resource for oData v4如何为 oData v4 指定 $resource 的 url
【发布时间】:2015-05-07 04:08:17
【问题描述】:

我正在关注damienbod's series on webapi and odata4,其中查询单个产品的 odata url 将是:

http://localhost/odata/Products(5)

问题是,我如何构建我的 $resource url 以映射到这个 url?我试过了

return $resource(appSettings.serverPath + "/odata/Products(:id)"

但是当我想查询集合时这会中断,在这种情况下生成的 url 是

http://localhost/odata/Products()

而不是

http://localhost/odata/Products

请告知我需要如何为此构建 $resource url?

【问题讨论】:

    标签: angularjs odata asp.net-web-api2


    【解决方案1】:

    您可以覆盖 query 操作的 URL,例如

    return $resource(appSettings.serverPath + '/odata/Products(:id)', {
        id: '@id' // I'm just assuming you have these default params
    }, {
        query: {
            method: 'GET',
            url: appSettings.serverPath + '/odata/Products',
            isArray: true
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2022-10-24
      • 2014-10-05
      • 2015-10-27
      • 1970-01-01
      • 2015-08-06
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 2015-04-16
      相关资源
      最近更新 更多