0
我正在拾取由對等方啓動的項目,並且遇到API調用問題。 這是我的角度控制器:無法繞過來自服務器的返回對象
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;
}]);
,並呼叫在這個函數中執行:
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);
});
};
};
問題,節約了音符後,noteObj是從回來原來的,而不是一個服務器(帶有_id字段)。 調試Note.prototype.save
,response.data
附帶了_id;
我需要知道如何在saveNote函數中訪問返回的Note對象。
就是這樣。非常感謝 –