如何使用两个参数生成ngResource url

时间:2017-04-05 04:57:52

标签: angularjs parameters ngresource

我试图使用angularjs中的ngResource生成此网址:

  

http://url_api/contact/58dc70f18e029b1338a97abc/address/58e3e3988e029a1aec5ad465

但我得到了这个:

  

http://url_api/contact/58dc70f18e029b1338a97abc/address?address_id=58e3e3988e029a1aec5ad465

这是我的工厂

var str = "123456789";
var res = str.match(/\d{3}(?=\d{6}|\d{3}|$)/g).join(".");
console.log(res);

这就是我以后称之为的方式

Recreating xxxxx_1
Recreating yyyyy_1
Creating zzzzz_1

ERROR: for server  'message'
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 64, in main
  File "compose/cli/main.py", line 116, in perform_command
  File "compose/cli/main.py", line 876, in up
  File "compose/project.py", line 416, in up
  File "compose/parallel.py", line 66, in parallel_execute
KeyError: 'message'
Failed to execute script docker-compose

请有人帮帮我吗?我赶时间

2 个答案:

答案 0 :(得分:1)

您需要在空对象中提及params。像这样:

factory('Addresses', function($resource) {
   return $resource(url_base + 'contact/:id/address',{
       id: '@id',
       addressId: '@addressId' 
   },{
       get: {
          method: 'GET', 
          isArray: true,
          url: url_base + 'contact/:id/address'
        },
        save:{
            method: 'POST'
        },
        delete:{
            method: 'DELETE',
            url: url_base + 'contact/:id/address/:addressId',
            // params:{
            //     id: '@_id',
            //     addressId: '@_addressId'
            // }
        }
    });
})

答案 1 :(得分:0)

url模板中的参数需要匹配调用中的参数:

    delete:{
        method: 'DELETE',
        url: url_base + 'contact/:id/address/:addressId',
        // params:{
        //     id: '@_id',
        //     addressId: '@_addressId'
        // }
    }
//WRONG address_id
//Addresses.delete({id:$scope.id_contact,address_id:address_id_delete})

//RIGHT addressId
Addresses.delete({id:$scope.id_contact,addressId:address_id_delete})