Skip to content

Instantly share code, notes, and snippets.

@guillefd
Last active February 6, 2018 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillefd/d946eddafcfcf11592b8b2e3676e6b07 to your computer and use it in GitHub Desktop.
Save guillefd/d946eddafcfcf11592b8b2e3676e6b07 to your computer and use it in GitHub Desktop.
Angular, form value change observer
import { Component } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
@Component({
selector: 'form',
templateUrl: `
<form [formGroup]="form">
<input type="text" formControlName="name">
</form>
`,
styleUrls: ['./form.component.scss']
})
export class FormComponent {
form: FormGroup;
construct(private fb:FormBuilder){
this.formChangeObserver();
}
private formChangeObserver() {
this.form.valueChanges
.subscribe(data => {
console.log('form changed ...');
});
}
private initForm() {
this.form = this.fb.group({
name: ['',[]]
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment