How to trigger reactive form valueChanges subscription only on input blur and enter key in Angular 2
if anyone in the future find this, there is actually something built into reactive forms for this, the updateOn
option:
new FormControl('', {updateOn: 'blur'});
this will cause valueChanges and validation and whatnot to only trigger on blur
You can combine blur and enter event into a subject and merge it with the valuechange Observable, so that it only fires value when blur or enter. I haven't fully tested the code just an idea and I have come across similar scenario before
// component
this.updateField=new Subject()
this.form.get('yourfield').valueChanges.withLatestFrom(updateField).map(res=>res[0]).subscribe()
//html
<input (blur)="updateField($event)" (keydown.enter)="updateField($event)"/>