0
我正在使用Angular 2和模態。關閉模式並重新打開後,所有舊數據仍可用。但我想重置所有數據。 任何幫助,將不勝感激。關閉模式後重新初始化ng-model數據
我正在使用Angular 2和模態。關閉模式並重新打開後,所有舊數據仍可用。但我想重置所有數據。 任何幫助,將不勝感激。關閉模式後重新初始化ng-model數據
您正在關閉模態。所以,在你的close
功能邏輯放置代碼來重置值。 您正在使用Component
作爲modals
,那麼您可以使用lifeCycle鉤子 ngOnDestroy
重置這些值。希望這可以幫助。
您的問題描述非常差。但爲什麼不直接使用,只是讓用戶與模型副本交互?一些僞代碼:
function onOpen() {
this.tempModel = Object.assign({}, this.realModel);
//or if you modal creates a new entity
//this.tempModel = {};
}
function onReset() {
//do nothing
}
function onSave() {
this.realModel = this.tempModel
}
你能分享一些代碼嗎? –