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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -