javascript - How to send post vars in angularjs Service -


how send post variables rest api using angularjs service?

right have this:

angularjsservices.factory('loginservice', [ '$resource',   function($resource){     return function(user, pass){       return $resource(baseurl + "/login", {}, {         login: {method:'post', params:{username: user, password: pass}, isarray:false}       });     }   }]); 

this way variables sent in url. (i'm using parts of this tutorial uses jquery instead of angularjs)

first of don't mix resource , service.

declare resource, this:

resourcemodule.factory('rsruser', [ '$resource',   function($resource){     return $resource(baseurl + "/login", {}, {         // removed params property, set pre-bound parameters action         login: {method:'post', isarray:false}     });   } ]); 

then can use resource rsruser in service or controller:

controllermodule.controller('ctrlmain', [ '$scope', 'rsruser',   function($scope, rsruser){     // create resource instance , attach properties (which become post body)     $scope.user = new rsruser     $scope.user.username = 'savior'     $scope.user.password = '123'      // call resource action     $scope.user.$login(function(){       //success callback     }, function() {       //error callback     })    } ]); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -