Проблема:
У консолі браузера ви бачите повідомлення про помилку, наприклад
pipe_async_fix.ts
core.mjs:6677 ERROR Error: NG0302: The pipe 'async' could not be found in the '_MyComponent' component. Verify that it is included in the '@Component.imports' of this component. Find more at https://angular.dev/errors/NG0302
at getPipeDef (core.mjs:29500:15)
at Module.ɵɵpipe (core.mjs:29441:19)
at MyComponent_Template (my.component.html:1:1)
at executeTemplate (core.mjs:11621:9)
at renderView (core.mjs:12828:13)
at renderComponent (core.mjs:12774:5)
at renderChildComponents (core.mjs:12876:9)
at renderView (core.mjs:12856:13)
at renderComponent (core.mjs:12774:5)
at renderChildComponents (core.mjs:12876:9)Рішення
Ця проблема зазвичай пов’язана з standalone-компонентами.
Відкрийте вихідний код .ts вашого компонента та додайте AsyncPipe до його імпортів:
async_pipe_import.ts
/* ... */
import { AsyncPipe } from '@angular/common';
@Component({
selector: 'app-my-component',
standalone: true,
imports: [
/* ...*/
AsyncPipe,
],
templateUrl: './my.component.html',
styleUrl: './my.component.scss'
})
export class MyComponent {Якщо ви не використовуєте standalone-компоненти, додайте AsyncPipe до imports модуля, у якому використовується ваш компонент
Дивіться схожі статті за категоріями:
Angular TypeScript
Якщо ця стаття допомогла вам, будь ласка, подумайте про те, щоб купити мені каву або зробити пожертву через PayPal на підтримку досліджень та публікації нових статей на TechOverflow