Circular dependency with Angular 2 and SystemJS [duplicate]

浪尽此生 提交于 2019-12-01 20:47:32
Günter Zöchbauer

You can't have a circular dependency this way. You can work around by using an interface

Plunker example

tata.ts

import { IToto } from './itoto';


export class Tata implements IToto {
  children: Toto[]
}

toto.ts

import { Tata } from './tata';
import { IToto } from './itoto';

export class Toto implements IToto{
  children: Toto[] = [];

  constructor(hasChildren: boolean = false) {
     ...
  }
}

itoto.ts

export interface IToto {
  children: Toto[]
}

See also Circular dependency injection angular 2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!