2015-06-19 49 views
1

我在找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」(如獲取提交每個輸入的值)?

+0

看看http://stackoverflow.com/questions/18240168/genuinely-stop-a-element-from-binding-unbind-an-element-angularjs – vitr

+0

有一個陰影模型。 OnSubmit將表單模型複製到真實模型 – Michael

回答

4

你應該使用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); 

您將使用臨時模型而不是「真實」模型。

+0

工作,謝謝! – BMaximus

相關問題