У меня проблемы с 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
Angular EventEmitter не работает время от времени ⇐ Javascript
Форум по Javascript
-
Anonymous
1744125277
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, когда я обновляю элемент.>
Подробнее здесь: [url]https://stackoverflow.com/questions/79562399/angular-eventemitter-does-not-work-at-times[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия