[英]How to not update a model until form submission in Angular?
我希望Angular在用戶提交表單之前不更新模型 。 或者,以另一種方式, 僅在用戶提交表單后才更新模型。
<form ng-submit="process()">
Value is : {{ model.property }}
<input type="text" ng-model="model.property">
<button type="submit">Submit</button>
</form>
我在想類似ng-model-options="{ updateOn: null }"
但是它不起作用。
如果沒有變得過於“ hacky”(例如在提交時獲取每個輸入的值),這是否有可能?
您應該使用angular.copy
克隆對象。
$scope.formData = angular.copy($scope.model);
<form ng-submit="process()">
Value is : {{ formData.property }}
<input type="text" ng-model="formData.property">
<button type="submit">Submit</button>
</form>
然后在處理中,您將更新模型。
$scope.model = angular.copy($scope.formData);
您將使用臨時模型,而不是“真實”模型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.