Angular 2 change event on every keypress

后端 未结 11 1432
说谎
说谎 2020-11-27 09:36

The change event is only called after the focus of the input has changed. How can I make it so that the event fires on every keypress?



        
11条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 10:01

    For Reactive Forms, you can subscribe to the changes made to all fields or just a particular field.

    Get all changes of a FormGroup:

    this.orderForm.valueChanges.subscribe(value => {
        console.dir(value);
    });
    

    Get the change of a specific field:

    this.orderForm.get('orderPriority').valueChanges.subscribe(value => {
        console.log(value);
      });
    

提交回复
热议问题