我想比較兩個表單的值是否相同。我有這個角2:比較2個表格
if(this.holdForm.value != this.positionForm.value){
this.enableButton = true;
}else{
this.enableButton = false;
}
但它不起作用。它不會使enableButton爲真。
更新:
this.positionForm = this.fb.group({
'name' : [position.name, Validators.required],
'remark': position.remark
});
this.holdForm = this.fb.group({
'name' : position.name,
'remark': position.remark
});
this.positionForm.valueChanges.subscribe(data => {
this.onValueChanged(data);
if(this.data.process == 'register'){
this.enableButton = true;
}else if(this.data.process == 'update' && this.holdForm.value != this.positionForm.value){
this.enableButton = true;
}else{
this.enableButton = false;
}
});
你得到的錯誤是什麼?你可以發佈兩種形式 –
我沒有錯誤。另一個是先前價值的臨時表格。我想比較是否有變化。看到更新的@RahulSingh – Char
你可以使用像lodash庫和它的平等方法來比較兩個對象 !_ isEqual(this.holdForm.value,this.positionForm.value) –