Angular EventEmitter не работает время от времениJavascript

Форум по Javascript
Ответить
Anonymous
 Angular EventEmitter не работает время от времени

Сообщение Anonymous »

У меня проблемы с Eventemitter Angular.@Output() public updatedIngredient = new EventEmitter();
< /code>
Функция для создания элемента следующая: < /p>
public async createIngredient(): Promise {
try {
if (this.ingredientForm.valid) {
const ingredient: Ingredient = {
name: this.ingredientForm.get('ingredientName')?.value,
description: this.ingredientForm.get('ingredientDesc')?.value,
type: this.ingredientForm.get('ingredientType')?.value,
};

await this.ingredientService.createIngredient(ingredient);

this.closeIngredientModal(true);
}
} catch (error: any) {
if (error.error.code === 'DUPLICATE_KEY') {
this.ingredientNameError = this.translateService.instant(
'APPS.YOUR_CHEF.INGREDIENT.error_existing_ingredient'
);
}
throw error;
}
}
< /code>
Функция для обновления элемента следующая: < /p>
public async updateIngredient(): Promise {
try {
if (this.ingredientForm.valid) {
const ingredientData: Partial = {
name: this.ingredientForm.get('ingredientName')?.value,
description: this.ingredientForm.get('ingredientDesc')?.value,
type: this.ingredientForm.get('ingredientType')?.value,
};

await this.ingredientService.updateIngredientById(
this.ingredient?._id || '',
ingredientData
);
this.closeIngredientModal(true);
}
} catch (error) {
throw error;
}
}
< /code>
Обе функции проходят через CloseRedIentModal, который отвечает как за закрытие модала создания /обновления элемента, так и излучения события, указывающего, был ли элемент создан или обновлен.public closeIngredientModal(createdOrUpdated: boolean) {
this.openedCreateModal = false;
this.ingredientNameError = '';

if (this.ingredient) this.initializeUpdateForm();
else this.initializeCreateForm();

this.updatedIngredient.emit(createdOrUpdated);
}
< /code>
Как вы можете видеть в этой функции, событие испускается для родителя, когда элемент был создан или обновлен, но я не знаю, почему, когда я обновляю элемент, это событие не испускается. Вот почему я не затрудняю, почему он не работает в EventeMitter, когда я обновляю элемент.>

Подробнее здесь: https://stackoverflow.com/questions/795 ... k-at-times
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»