2016-12-18 50 views
1

創建表單時如何訪問formControl我有下面的代碼通過formBuilder在Angular2

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); 
     }); 

    }); 
} 

我想訂閱的titlevalueChanges,但我得到Cannot read property 'valueChanges' of undefined錯誤。

我可以訂閱this.profileForm.valueChanges,但當標題發生變化時,我想進行某種去抖動和api調用。

看來如果您有FormControl您將能夠訂閱它的更改,但由於我使用FormBuilder語法,因此我無權訪問FormControl

回答

1
this.profileForm.get('title').valueChanges...