angularjs $资源而不是取代变量网址模板POST [英] angularjs $resource not replacing variable in url template for POST

查看:168
本文介绍了angularjs $资源而不是取代变量网址模板POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AngularJS 1.2.16和角资源1.2.16。

Using AngularJS 1.2.16 and angular-resource 1.2.16.

我有这样的资源:

$resource('api/:variable/path',
    {
        variable:'@variableName'
    });

当我做了获取使用像

resourceIns.get({variable:'taco'});

由此产生的AJAX调用替换:变量正确,我也得到

The resulting ajax call replaces :variable properly and i get

api/taco/path

如果我做一个像后

resourceIns.save({variable:'taco'});

所产生的Ajax调用看起来像

the resulting ajax call looks like

api/path

和塔科被放在POST身体...

and 'taco' gets put in the POST body...

我有麻烦找别人抱怨这个的话,也许这是什么应该发生的?

I've had trouble finding others complaining about this so, maybe this is what's supposed to happen?

编辑:我刚刚发现,获得使用变量和保存/ POST在上面的例子中使用了'VARIABLENAME。任何人有一个解释是什么?

edit: I just discovered that get uses 'variable' and save/POST uses 'variableName' in the above example. Anybody have an explanation for that?

下面是呈现的情况小提琴:小提琴

Here's a fiddle showing the situation: fiddle

推荐答案

我跨$以同样的方式psented本身p $同一个问题或一个人赶紧跑去。我的资源,也没有尊重通过.POST方法传入的参数。

I ran across the same issue or one that presented itself in the same fashion. My resource, too, was not respecting parameters passed in through a .post method.

我能得到它的直接在预期的参数传递

使用$资源:

angular.module('myApp')
  .factory('ModuleProductProducts', function ($resource) {
    return $resource('/module-api/product-products/:siteId/:id/:controller', {
      id: '@id'
    },
    {
        'updateMedia': {
            method: 'POST',
            url: 'module-api/product-products/:id/media/:mediaId',

            // *** Here ***
            params: {
                id: '@id',
                mediaId: '@mediaId'
            }
            // ************
        }
    });
  });

这篇关于angularjs $资源而不是取代变量网址模板POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆