javascript - Angular $resource 从 REST 查询字符串中删除问号

标签 javascript angularjs rest

嗨,我想知道是否有人可以帮助我更改查询字符串的格式。目前它的格式如下:

/api/foo?id=AD12JK23

但是我该如何将其更改为以下格式:

/api/foo/AD12JK23

我的代码如下:

.state('foo-details', { 
    url: '/foo-details/:fooRefrence'
    }
 })

var ref = $stateParams.fooRefrence;
        $scope.fooDetails = myApi.Foo.get(
            {
                 id: ref
            }
        );

.factory('myApi', ['$resource', function ($resource) {
    return {

        Foo: $resource('/api/foos', {id: '@ref' },

    }
}])

感谢您的帮助。

最佳答案

查看资源引用以了解执行此操作的适当方法。 https://docs.angularjs.org/api/ngResource/service/$resource#usage

我想如果你这样写你的资源url,就能解决问题:

.factory('myApi', ['$resource', function ($resource) {
    return {
        // Add :id at the end of the url
        // Also change @ref to @id, the word you use after @ is the same as 
        // the key of the object you use to call the resource with
        Foo: $resource('/api/foos/:id', {id: '@id' },

    }
}])

关于javascript - Angular $resource 从 REST 查询字符串中删除问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25743497/

相关文章:

android - 使用 GSON 库从 URL(RESTful web 服务)解析 JSON 字符串。安卓

mysql - Nodejs连接数据库或REST服务

javascript - KineticJS - 基本的 javascript 范围问题

javascript - 当用户单击外部图像时尝试更改标记的图标

javascript - 使用 Web.config 中的选项填充 HTML 选择

javascript - AngularJS拦截器重试请求

javascript - 如何从 Angular 中的指令获取值

mysql - 几个异步函数后的一个响应

javascript - 将相似的 jQuery 函数分组

javascript - Durandal 激活,子路由器的分离事件永远不会被触发