How to access formControl when creating a form via formBuilder in Angular2

287 views Asked by At

I have below code

ngOnInit() {

  this.contactsService.getContactByAuthId(this.user.id).subscribe(profile => {
    this.profile = profile;
    this.profileForm = this.formBuilder.group({
      name: [this.profile.name, Validators.compose([Validators.minLength(6), Validators.required])],
      title: [this.profile.title, Validators.compose([Validators.minLength(6), Validators.required])],
      });

    this.profileForm.title.valueChanges.subscribe(value => {
        console.log(value);
        });

  });
}

I want to subscribe to valueChanges of title, but I get Cannot read property 'valueChanges' of undefined error.

I am able to subscribe to this.profileForm.valueChanges but I want to do some kind of debounce and api call when the title is changed.

It seems that if you have FormControl you will be able to subscribe to it's changes but since I am using FormBuilder syntax, I don't have access to FormControl.

1

There are 1 answers

0
Günter Zöchbauer On BEST ANSWER
this.profileForm.get('title').valueChanges...