حل مشكلة التنقل داخل النظام

مشكلة NG0200: Circular dependency in DI detected

  حل هذه المشكلة يكون من الـ Module


اتبع الكود أدناه:

https://github.com/JanMalch/hot-toast-circular-app-ref



يكون الحل عن طريق إنشاء مجلد وتسميته Loader



محتوى ملف interceptor.service.ts كالتالي:

import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { finalize } from 'rxjs/operators';
import { LoaderService } from './loader.service';

@Injectable({
  providedIn: 'root'
})
export class InterceptorService implements HttpInterceptor {

  constructor(public loaderService:LoaderService) { }
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.loaderService.isLoading.next(true);
return next.handle(req).pipe(
  finalize(
    ()=>{
      this.loaderService.isLoading.next(false);
    }
  )
);
  }
}


أما ملف loader.service.ts فهو كالتالي:

import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class LoaderService {
public isLoading: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
  constructor() { }
}


من ثم نستدعي هذين الملفين إلى الـ app.module.ts

  providers: [
    // {provide: LocationStrategy, useClass: HashLocationStrategy},
    DatePipe,
    { provide: HTTP_INTERCEPTORS, useClass: BasicAuthInterceptor, multi: true },
    { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
    // {
    //   provide: ErrorHandler, useClass: FirebaseService
    // },
    // {
    //   provide: ErrorHandler, useClass: AuthenticationService
    // },
    { provide: HTTP_INTERCEPTORS, useClass: InterceptorService, multi: true }
  ],







تعليقات

المشاركات الشائعة من هذه المدونة

ngx-extended-pdf-viewer

how to getting access token for https://fcm.googleapis.com/v1/projects/al-ayahya-co/messages:send for angular and backend nestjs

طريقة تفعيل زر Inline Keyboard في Telegram Bot