Hello I want to disable a filed/drop-down based on conditions angular form builder:
I have 3 drop downs, first drop down will be loading while page loading.. when I select the option in first drop-down second should be enabled, when I select the option in second third should be enabled.
here is what I tried:
ngOnInit(): void {
this.someMethodToFetchDataForSelectbox();
this.method1.subscribe(data => {
this.data= data;
}
);
this.constructForm();
}
constructForm() {
this.form = this.fb.group({
listOfFruits: [''],
listOfAnimals: [''],
listOfLetters: ['']
});
this.form.get('listOfAnimals').disable();
this.form.get('listOfLetters').disable();
this.form.controls.listOfFruits.valueChanges.subscribe(value=>{
his.forms.controls.listOfAnimals.enable();
this.form.get('listOfLetters').disable();
//method to fetch list of animals from DB
fetchAnimals(value) ;
});
}
fetchAnimals(value) {
this.form.controls.listOfAnimals.valueChanges.subscribe(value=>{
this.forms.controls.listOfLetters.enable();
//method to fetch list of letters from DB
fetchLetters(value) ;
});
}
I tried the above but it is not working..