우선, 서버는 관련성이있는 오류를 반환해야합니다. HTTP 오류 상태 코드 (4xx 및 5xx 코드 참조). 이렇게하면 오류 콜백에서 오류 만 처리합니다.
function onError (response){
switch (response.status) {
case 400:
case 404:
//etc...
response.data.errors.forEach(function(error){
$scope.alerts.push({type:'danger', msg: error.msg});
});
break;
case 500:
$scope.alerts.push({type:'danger', msg: "There was a problem saving your data: " + response.data});
break;
}
}
즉, $ scope.user는 a $ 리소스 인스턴스, 그러면 서버에서 다시 가져올 필요가 없다면 $ save () 메소드는 객체를 변경하지 않습니다.
서버에서 $ scope.user로 검색된 '사용자'객체에서 값을 복사하려면 Angular.extend ()
angular.extend($scope.user, data) //this updates $scope.user with data attributes.
주목할 가치가 있습니다 angular.extend
필요한 경우 딥 카피를 수행하지 않습니다. jQuery.extend:
jQuery.extend(true, $scope.user, data)