Created
October 17, 2013 18:16
-
-
Save paul-english/7029656 to your computer and use it in GitHub Desktop.
Angular resource doesn't bind urlParameters for
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
api = $resource('http://127.0.0.1/api/v1/:type/:id', | |
{ | |
type: '@type' | |
id: '@id' | |
}, | |
{ | |
get: {method: 'GET'} | |
post: {method: 'POST', headers: {'Content-Type': 'application/json'}} | |
del: {method: 'DELETE', headers: {'Content-Type': 'application/json'}} | |
create: {method: 'POST', headers: {'Content-Type': 'application/json'}} | |
update: {method: 'PUT', headers: {'Content-Type': 'application/json'}} | |
} | |
) | |
User = api.bind({type: 'user'}) | |
User.get({}, (user_response)-> | |
users = user_response.objects | |
user = users[0] | |
user.name = "John" | |
user.update() # This will fail, as it doesn't know the default type parameter | |
user.update({type: 'user'}) # This will work | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment