I'm angular8 and I have a form array inside of form group but I want to detect new changes of a certain input.
ngOnInit(): void {
this.makeForm = this.fb.group({
year:['', Validators.required],
amount:['', Validators.required],
desc:['', Validators.required],
details: new FormArray([
this.det(),
])
})
det(){
return new FormGroup({
requestfor : new FormControl(''),
remarks : new FormControl('')
})}
I have to check the data that every value changes in formarray values. But I am getting error if I use
this.makeForm.value.details.get('requestfor').valueChanges
and the error is
ERROR TypeError: Cannot read property 'valueChanges' of undefined
how to get the value inside of form array value
How to get the value.....
You need subscribe to valuesChanges, when you create the FormGroup
You can also has an array of Observables, and pass the index to your function detAnd when you add or delete a new group to the formArray subscribe to a forkJoin of the arrayUpdate If we want control the whole array, we can define an array of observables and a subcriptions:
We need make a function where we are going to subscribe to a CombineLastest
We call to this function, when remove an element
And in function group Array add a new element to this.observables
NOTE: I this last part of code I use a getter
The stackblitz