AngularJS的数据绑定很整洁,但我不希望在用户按下“保存”按钮之前立即更新我的视图。如何在保持文本输入和{{placeholders}}
之间的绑定的同时延迟更新视图?
答案 0 :(得分:5)
您可以仅为表单绑定临时对象,并让“保存”按钮处理程序将表单对象复制到主数据模型中。
以下是示例: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 }}
在js:
app.controller('MainCtrl', function($scope) {
$scope.formobj = {name: ""};
$scope.obj = {name: ""};
$scope.update = function() {
$scope.obj = angular.copy($scope.formobj);
};
});