У меня есть угловой модал, который сделан из нескольких вкладок. На одной вкладке при рассеивании на флажке некоторые другие поля отключены. Однако, когда я снова переключаю вкладку, поля становятся включенными. Я использовал конфигурацию формы JSON для динамического создания моего HTML, поэтому не могу использовать ViewChild. Помощь, пожалуйста: (< /p>
ngAfterViewInit(): void {
this.dishCategories = this.menuService.getDishCategoryFromToken();
if (!Array.isArray(this.dishCategories)) {
this.dishCategories = this.dishCategories ? [this.dishCategories] : [];
}
if (this.dishCategories.includes('SpicySpecials')) {
this.prepareSauce();
this.disableSides();
this.toggleSpicyLevel();
this.cdr.detectChanges();
}
}
private disableSides() {
const isExtraSpicy = this.dynamicOrderForm.get('extraSpicy');
const spicyLevelInput = this.dynamicOrderForm.get('spicyLevel');
const sideDishesAcc = this.dynamicOrderForm.get('sideDishes');
const drinkSelection = this.dynamicOrderForm.get('drinkSelection');
const dessertOption = this.dynamicOrderForm.get('dessertOption');
if (isExtraSpicy?.value == false) {
drinkSelection?.enable();
spicyLevelInput?.disable();
sideDishesAcc?.disable();
if (drinkSelection?.value == false)
{
dessertOption?.disable();
}
} else {
drinkSelection?.reset(false);
drinkSelection?.disable();
dessertOption?.disable();
}
if (isExtraSpicy) {
isExtraSpicy.valueChanges.subscribe((newValue) => {
if (newValue === true) { // extra spicy selected
spicyLevelInput?.enable();
drinkSelection?.patchValue(false);
drinkSelection?.disable();
const dessertElement = document.querySelector(`.dessertSelect select`) as HTMLSelectElement;
dessertOption?.patchValue(null);
dessertElement.selectedIndex = 0;
dessertElement.disabled = true;
sideDishesAcc?.enable();
} else { // no extra spice
const spicyLevelElement = document.querySelector(`.spicyLevel input`) as HTMLInputElement;
console.log('element:', spicyLevelElement
Подробнее здесь: https://stackoverflow.com/questions/794 ... tching-tab