-
-
Save teamon/7678184 to your computer and use it in GitHub Desktop.
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
| db = { | |
| person: { | |
| save: function(obj){ | |
| if(obj.id){ | |
| return $http.post("/person", obj).then(function(res){ | |
| var data = angular.extend({}, obj); // create copy of `obj` + `id` field | |
| data.id = res.data.id; | |
| return data; | |
| }) | |
| } else { | |
| return $http.put("/person", obj) | |
| } | |
| } | |
| } | |
| } | |
| var person = {firstName: 'John', lastName: 'Smith'} | |
| db.person.save(person).then(...) | |
| person.firstName = "Michael" | |
| db.person.save(person).then(...) |
Author
Ad 2. But it doesn't mean your person object will be modified, right? You would have to modify it in then callback:
.then(function(success){
person = success.data;
});
Do I miss anything?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Promise#thentransforms promise value so nextthencall will receive modified object