我在列表中有一个对象。称之为$ scope.contact
我对终点进行PATCH并成功返回。但是,我无法弄清楚如何使用新信息更新$ scope.contact。
这是我的第一个完整的应用程序,所以我确定我犯了一个愚蠢的错误。随意链接到我错过的文档或我没有得到的原则。
到目前为止,这是我的控制器:
contactControllers.controller('ContactDetailController', ['$scope', 'growl', 'Restangular', function($scope, growl, Restangular) {
$scope.editContact = function() {
Restangular.one('contacts', $scope.contact.id).patch($scope.contact).then(function(contact) {
$scope.contact = contact;
// I can't figure out what is supposed to go here.
// If I do .push(contact) I get undefined errors.
growl.addSuccessMessage("Your contact was edited!");
},function(response) {
console.log('Error with status code: ', response.status);
});
}
}])
答案 0 :(得分:0)
更新:因为它不是一个数组而且它是一个对象,这是我的控制器方法 然后包装scope.vontact =联系eith apply方法,如下
$scope.$apply(function() {
$scope.contact=contact;
});
所以完整的控制器将是
contactControllers.controller('ContactDetailController', ['$scope', 'growl', 'Restangular', function($scope, growl, Restangular) {
$scope.editContact = function() {
Restangular.one('contacts', $scope.contact.id).patch($scope.contact).then(function(contact) {
$scope.$apply(function () {
$scope.contact = contact;
});
// I can't figure out what is supposed to go here.
// If I do .push(contact) I get undefined errors.
growl.addSuccessMessage("Your contact was edited!");
},function(response) {
console.log('Error with status code: ', response.status);
});
}
}])