Angular2 ngModelChange previous value

前端 未结 4 1522
醉酒成梦
醉酒成梦 2020-12-25 11:13

Is there a way to get the previous(last) value of a field on ngModelChange? What I have goes something like this

HTML



        
4条回答
  •  时光说笑
    2020-12-25 11:55

    all you need to do is to put (ngModelChange)="textChanged($event)" to the left of [(ngModel)] element in the html tag, like:

    
    

    This way, inside textChanged(event), the element you are binding to still has the previous value, while event is the new one

    If you type

    
    

    The event will be called with new value only. However:

       - 
    

    Will get you both events with previous and current value

提交回复
热议问题