51

providedIn新しい属性を介して解決サービスを提供しようとしています。

これは、保護されたモジュールで使用する翻訳リゾルバーです。

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

import { Observable , pipe } from 'rxjs';
import {map} from "rxjs/operators";

//This is causing: "WARNING in Circular dependency detected:"
import {ProtectedModule} from "../../../protected/protected.module";

import { HttpHandlerService } from '../../http/http-handler.service';

@Injectable({
  providedIn: ProtectedModule //Over here (I need the import for this line)
})
export class TranslationsResolverService {
  constructor(private _httpHandlerService : HttpHandlerService) { }
    resolve(): any {
      //Do Something...
    }
}

保護されたルーティング モジュールで変換リゾルバー サービスを宣言しました。

import { NgModule }           from '@angular/core';
import {RouterModule, Routes} from '@angular/router';

import {AuthGuard} from "../core/resolvers/auth/auth.guard";
import {TranslationsResolverService} from "./../core/resolvers/translations/translations-resolver.service";

const routes: Routes = [
  {
    path : 'app' ,
    component: ProtectedComponent,
    resolve : {
      translations : TranslationsResolverService // <---- Over here - i can't remove that of course
    },
    canActivate: [AuthGuard],
    ]
  }
];


@NgModule({
  imports : [RouterModule.forChild(routes)],
  exports : [RouterModule]
})
export class ProtectedRoutingModule { }

属性で使用するためにインポート (typescript インポート) しprotected.moduleたため、検出された循環依存関係で警告が表示されます。translations-resolver.service.ts providedIn

path/to/translations-resolver.service.ts -> 

protected/protected.module.ts ->

protected/protected-routing.module.ts -> 

path to translations-resolver.service.ts

属性により、2 番目のパス (protected/protected.module.ts) が追加されprovidedInます。

を(providers 配列で)translationsResolverとして提供するだけでこれを修正できますが、私はそれをプロバイダーにすることを好みます。NgModule providerinjectable

これを解決するための提案はありますか?

4

5 に答える 5