Angular 2 ngModelChange old value

后端 未结 3 1808
野的像风
野的像风 2020-12-11 01:56

Can someone please tell me what is the best practice for comparing ngModel old and new value?

In angular 1:

$scope.$watch(\'someProperty\', funciton(         


        
3条回答
  •  旧巷少年郎
    2020-12-11 02:30

    This might work

    (ngModelChange)="onModelChange(oldVal, $event); oldVal = $event;"
    

    or

    (ngModelChange)="onModelChange($event)"
    
    oldValue:string;
    onModelChange(event) {
      if(this.oldValue != event) {
        ...
      }
      this.oldValue = event;
    }
    

提交回复
热议问题