export class ApplyComponent implements OnInit {
formApply: FormGroup;
postCodeInput: boolean = true;
constructor(private fb: FormBuilder) {}
ngOnInit() {
this.formApply = this.fb.group({
firstName: ["", Validators.required],
currentUKAddress: this.fb.group({
flat: ["", Validators.required],
years: ["", Validators.required]
})
});
this.onChanges();
}
onChanges(): void {
...
}
I am trying to track changes in the years field. Despite my attempts within the onChanges()
method, I can't figure out why nothing seems to be working...
I have tried:
- this.formApply.get('currentUKAddress.years').valueChanges.subscribe(data => {
console.log('Form changes', data);
})
- this.formApply.controls.currentUKAddress.get('years').valueChanges.subscribe(data => {
console.log('Form changes', data);
})
- this.formApply.controls.currentUKAddress.controls['years'].valueChanges.subscribe(data => {
console.log('Form changes', data);
})
and various other approaches. However, each time I encounter a Typescript compiler error stating either: property does not exist on type AbstractControl or Object is possibly null.