Currently, I have taken over a project initiated by a colleague, and I am encountering difficulties with an API call. Here is the snippet of my angular controller code:
angular.module('oowli').factory('Note', ['$http', function($http) {
var Note = function(data) {
angular.extend(this, data);
};
Note.prototype.save = function() {
var note = this;
return $http.post('/notes', this).then(function(response) {
note = response.data;
}, function(error) {
return error;
});
};
return Note;
}]);
The API call is made within this function:
var saveNote = function(Note, scope){
return function(span, phrase){
var noteObj = new Note({
user: scope.global.user._id,
content: span.innerText
});
noteObj.save().then(function(){
console.log(noteObj);
});
};
};
My concern lies in the fact that after saving the note, the noteObj remains unchanged instead of being updated with the returned object from the server (containing an _id field).
Upon debugging within the Note.prototype.save
, it is evident that response.data
contains the _id;
I am seeking guidance on how to access the updated Note object within the saveNote function.