English 中文(简体)
How do I make the Prime MessageService work in the Interceptor of an Angular application that only uses Standalone Components?
原标题:

I m trying to implement a global error notification but I m not managing to inject anything into the Interceptor and the worst thing is that it doesn t give an error, it just doesn t work, if anyone can shed some light, I d appreciate it, below project specifications -Angular v16 -Full standalone -PrimeNG

main.ts

bootstrapApplication(AppComponent, {
  providers: [
    provideRouter(routes),
    provideAnimations(),
    provideHttpClient(withInterceptors([ErrorHandlerInterceptor])),
    importProvidersFrom(MessageService, ToastModule),
  ],
}).catch((err) => console.error(err));

error-handler.interceptor.ts

export const ErrorHandlerInterceptor: HttpInterceptorFn = (req, next) => {
  console.log( here comes );
  const messageService: MessageService = inject(MessageService);

  console.log( Not here );

  messageService.add({
    severity:  success ,
    summary:  Success ,
    detail:  Message Content ,
  });

  return next(req).pipe(
    catchError((error) => {
      if (error.status === 0) {
      }
      if (error.status === 500) {
      }
      console.log( cath );
      return throwError(() => new Error(error));
    })
  );
};

I tried to create a service with the MessageService inside and even then it didn t help and it doesn t return any error, the HTTP call simply goes to limbo.

问题回答

暂无回答




相关问题
Angular matSort not working on Date column by desc

Trying to sort the material table with date column , date format is MM/DD/YYYY ,h:mm A , order of date is not by latest date and time. Anything which i missed from the below stackblitz code. https:/...

热门标签