Angular 1.0.8 $resource with multiple optional get parameters

前端 未结 1 534
南方客
南方客 2021-02-02 16:24

My Student ulr looks like this:

var Student = $resource(\'/app/student/:studentid:courseId\',
    {studentid:\'@id\',courseId:\'@cid\'}
);

When

1条回答
  •  悲哀的现实
    2021-02-02 17:08

    If you need parameters to be mapped to the query parameters, not the path parameters, you shouldn't put the name of parameters into the path. E.g. student resource should look like this:

    var Student = $resource('/app/student/',
        {}
    );
    

    Then invocation like this will work without any problems:

     Student.get({id:12,courseId:55});//calls /app/student/?id=12&courseId=55
     Student.get({id:12});//calls /app/student/?id=12
     Student.get({courseId:55});//calls /app/student/?courseId=55
    

    The others cases will work as well. Just don't confuse path parameters with query parameters.

    0 讨论(0)
提交回复
热议问题