Created
September 16, 2013 07:13
-
-
Save harshalbhakta/6577525 to your computer and use it in GitHub Desktop.
Angular resource with additional methods.
This file contains hidden or 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
| app.factory "User", ["$http","$resource",($http,$resource) -> | |
| User = $resource("/roles/:id", {id: "@id"}, {update: {method: "PUT"}}) | |
| # Initialize the data using a static method | |
| User.init = (data) -> | |
| angular.extend this, data | |
| # a static method to retrieve User by ID | |
| User.get_it = (id) -> | |
| $http.get("/roles/" + id).then (response) -> | |
| new User.init(response.data) | |
| # an instance method to create a new Book | |
| User::create = -> | |
| user = this | |
| $http.post("/roles/", user).then (response) -> | |
| user.id = response.data.id | |
| user | |
| User | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment