mpen
mpen

Reputation: 283043

Non-immediate updating model?

AngularJS's data-binding is neat, but I don't want my view to be immediately updated until the user presses a "save" button. How can I delay updating the view while still keeping the binding between my text inputs and {{placeholders}}?

Upvotes: 4

Views: 1048

Answers (1)

Tosh
Tosh

Reputation: 36030

You can bind the temporary object just for the form and let "save" button handler to copy the form object into your main data model.

here is the example: http://plnkr.co/edit/4vuduD

in html:

<form ng-submit="update()">
  <label>name: <input ng-model="formobj.name"/></label>
  <input type="submit"/>
</form>
saved name : {{ obj.name }}

in js:

app.controller('MainCtrl', function($scope) {
  $scope.formobj = {name: ""};
  $scope.obj = {name: ""};
  $scope.update = function() {
    $scope.obj = angular.copy($scope.formobj);
  };
});

Upvotes: 5

Related Questions