我试图通过新的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导入)translations-resolver.service.ts
in order to use it in the 102 attribute中的protected.module
,我在检测到循环依赖关系时收到一条警告:
path/to/translations-resolver.service.ts ->
protected/protected.module.ts ->
protected/protected-routing.module.ts ->
path to translations-resolver.service.ts
第二个路径(protected/protected.module.ts)是由于providedIn
属性而添加的.
我可以通过将translationsResolver
作为NgModule provider
(在提供者数组中)提供来解决这个问题,但我更喜欢它是injectable
提供者.
有解决这个问题的建议吗?