Skip to content

Instantly share code, notes, and snippets.

@ringoluo
Created February 25, 2015 08:46
Show Gist options
  • Save ringoluo/79648ba793787e860e11 to your computer and use it in GitHub Desktop.
Save ringoluo/79648ba793787e860e11 to your computer and use it in GitHub Desktop.
AngularJS Rollback value with ng-change
$scope.$watch('color', function(newValue, oldValue) {
$scope.previousColor = oldValue;
});
$scope.changeColor = function(){
$http.put('...', {color: $scope.color}).error(function(){
$scope.color = $scope.previousColor;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment