Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created May 17, 2014 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronksaunders/8bc271c24c15140fcfc2 to your computer and use it in GitHub Desktop.
Save aaronksaunders/8bc271c24c15140fcfc2 to your computer and use it in GitHub Desktop.
Way too long to figure out how to add post data in $resource in angularjs
angular.module('Ionicgram', ['ionic', 'Ionicgram.controllers', 'Ionicgram.services'])
.run(['$ionicPlatform', '$rootScope', '$state', 'UserService', function ($ionicPlatform, $rootScope, $state, UserService) {
$ionicPlatform.ready(function () {
UserService.login({
login: "admin",
password: "admin_password"
},function(_result){
console.log("_result " + JSON.stringify(_result));
alert(_result.username);
}, function(_error){
console.log("_error " + JSON.stringify(_error));
alert(JSON.stringify(_error));
});
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
}])
angular.module('Ionicgram.services', ['ngResource'])
.factory('UserService', ['User', '$resource', function (User, $resource) {
var currentUser = null;
var acs_api_key_development = "YOUR-API-KEY";
var service = $resource('https://api.cloud.appcelerator.com/v1/users/:action', {},
{
login: {
// POST BODY DATA
login: '@login',
password: '@password',
// URL PARAMETERS
params: {
action: 'login.json',
key: acs_api_key_development
},
method: "POST",
isArray: false,
transformResponse : function(data,headers) {
return (data && User.build(JSON.parse(data).response.users[0]));
}
}
});
return service;
}])
@aaronksaunders
Copy link
Author

If someone knows where this is clearly documented please let me know because I was googling around for hours to find a viable solution that worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment