Created
May 17, 2014 03:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}); | |
}]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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