angularjs - Add a custom method to $resource in Angular JS -


i have written custom method call api passing parameters, following error: typeerror test.testing not function. followed code in here: https://docs.angularjs.org/api/ngresource/service/$resource

this code use, $save example working fine.

i using version 1.4.1.

services.factory('calendar',function($resource){     return $resource('/api/calendar/:id',{         update: {             method: 'put'         },         testing: {             method: "post", params:{charge:true}         }     }); });  function( $scope, calendar ) {          var test = new calendar();         test.title = "hello";         test.$testing();         ... } 

the reason because haven't quite followed example in docs. see:

angular.module('testapp', [])   .factory('creditcard', creditcard)   .factory('calendar', calendar);  function creditcard() {   return $resource('/user/:userid/card/:cardid',       {userid:123, cardid:'@id'}, {       charge: {method:'post', params:{charge:true}}   }); }  function calendar() {     return $resource('/api/calendar/:id',     {id: 200},     {       update: {           method: 'put'       },       testing: {           method: "post", params:{charge:true}       }   }); } 

as can see added second object argument {id:200} tells ng-resource in order fill out /api/calendar/:id correctly needs pull property id object , use value.


Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -