无法理解角度6错误

时间:2018-07-17 09:39:10

标签: angular angular6

我正在将现有项目从5号角移到6号角,但我陷入了这个错误:

findNavController(nav_host_fragment).addOnNavigatedListener { controller, 
 destination ->
 when(destination.id) {
    R.id.destination1 -> {
        //Do something with your toolbar or BottomAppBar
    }
    R.id.destination2 -> {
        //Do something with your toolbar or BottomAppBar
    }

 }
}

我不知道如何确定循环依赖性。

这里是AppModule

Uncaught Error: Provider parse errors:
Cannot instantiate cyclic dependency! ErrorHandler ("[ERROR ->]"): in NgModule 
AppModule in ./AppModule@-1:-1

1 个答案:

答案 0 :(得分:1)

循环依赖性意味着有两个服务(提供者)在它们的依赖性中相互依赖,例如,假设您有Service2@Injectable({providedIn:'root'}) export class Service1 { constructor(private service2: Service2){} }

service1.ts:

@Injectable({providedIn:'root'})
export class Service2 {
    constructor(private service1: Service1){}
} 

service2.ts:

Service1

所以angular无法创建它们,因为它需要Service2实例来创建Service2实例,但是同时它需要Service1实例来创建let counts = new Map, arr = [1, 3, 2]; for (let i = 0; i < arr.length; i++) { let num = arr[i]; counts.set(num, (counts.get(num) || 0 ) + 1); } console.log(Array.from(counts.entries(), ([value, count]) => ({ value, count })));实例。 / p>

您的情况可能更复杂,但是要寻找这种依赖性