У меня есть флажок, в котором при нажатии на него он должен привести к отключению входов и раскрываний. Я сделал изменение на своей местной машине, и все работает нормально. Однако в моей среде я получаю элемент Null, вызывая его не отключен. < /P>
private disableControls() {
const isPizza = this.dynamicFormMenuForm.get('menuHasPizza');
const pizzaOptions = this.dynamicFormMenuForm.get('menuPizzaOptions');
const pastaOptions = this.dynamicFormMenuForm.get('menuPastaOptions');
const saladChoice = this.dynamicFormMenuForm.get('menuSaladChoice');
const dessertChoice = this.dynamicFormMenuForm.get('menuDessertChoice');
if (isPizza?.value == false) {
saladChoice?.enable();
pastaOptions?.enable();
pizzaOptions?.disable();
if (saladChoice?.value == false) {
dessertChoice?.disable();
}
}
else {
saladChoice?.reset(false);
saladChoice?.disable();
dessertChoice?.disable();
}
if(isPizza){
isPizza.valueChanges.subscribe
((newValue) => {
if (newValue === true) { // Pizza
selected
pizzaOptions?.enable();
saladChoice?.patchValue(false);
saladChoice?.disable();
const dessertElement = document.querySelector(`[ng-reflect-name="menuDessertChoice"]`) as HTMLSelectElement;
dessertChoice?.patchValue(null);
dessertElement.selectedIndex = 0;
dessertElement.disabled = true;
const pastaElement = document.querySelector(`[ng-reflect-name="menuPastaOptions"]`) as HTMLSelectElement;
pastaOptions?.patchValue(null);
pastaElement.selectedIndex = 0;
pastaElement.disabled = true;
}
});
< /code>
}
} .. В селекторе запросов элементы являются нулевыми и, следовательно, не отключены в среде. Я вызываю функцию на ngafterviewinit
Подробнее здесь: https://stackoverflow.com/questions/794 ... y-selector