私の角型アプリケーションでは、私は、インジェクタを返すAppInjectorと呼ばれるグローバル変数があります。この変数はAppModule
に設定されています。角2:グローバルAppInjector。どのように警告 "循環依存"を回避する
export let AppInjector: Injector;
@NgModule({
declarations: [
AppComponent,
],
bootstrap: [AppComponent],
})
export class AppModule {
constructor(private injector: Injector) {
AppInjector = this.injector;
}
}
は私がAppInjector
特別なサービスの助けを借りて取得するいくつかのヘルパー関数を持っています。ヘルパー関数は別々のファイルにあり、どのコンポーネントにも属していません。たとえば:。。?
function initNodeTemplate() {
diagram.nodeTemplateMap.add(NodeCategory.Question,
GO(go.Node, "Auto",
{
click: (evt, obj) => {(AppInjector.get(MyService) as MyService).myFunction(obj)},
},
// other stuff ...
));
}
問題は角コンパイラが原因AppInjector
の循環依存(WARNING in Circular dependency detected: src\app\app.module.ts -> src\app\frame\frame.module.ts -> src\app\designer\designer.module.ts -> src\app\designer\designer.component.ts -> src\app\designer\helpers\templates.helper.ts -> src\app\app.module.ts
について私に警告していることである
私はこの警告を取り除くことができますどのように 私がいることを知っていますこの場合、私はinitNodeTemplate()
にパラメータとしてdetailService
を渡すことができましたので、私はもうAppInjector
を必要としません。しかし、私は自分の機能をうんざりさせたくありませんこのサービスのパラメータ。
サイクルを解除します。それを引き起こすコードを見ずにどうやって正確に伝えるのは難しいです。 https://stackoverflow.com/questions/41585863/angular2-injecting-services-in-custom-errorhandler/41585902#41585902 –