I have a huge model-driven form which it's fields may affect each other's behavior, For example:
If value of field A changes, Value of field B should be obtained from server,Or if value of field C changes, Field D should be disabled & etc.
In order to detect the changes I use valueChanges:
this.form.controls['a'].valueChanges.subscribe(data=>{
//do some staff
});
this.form.controls['b'].valueChanges.subscribe(data=>{
//do some staff
});
.
.
.
(Note that I can't say this.form.valueChanges
because my form has about 50 fields). Everything looks fine but this approach makes my ngOnInit()
a little messy. My question is:
Is there any better/more efficent solution for situations like this?Subscribing too many observables in ngOnInit doesn't make any problems?How can I improve my code?