Angular 6 - can't resolve all parameters for AppComponent

前端 未结 10 909
时光取名叫无心
时光取名叫无心 2021-02-07 11:59

I am trying to build an application with Angular 6 and I am still setting everything up. But it seems there is something wrong with the dependency injection in my app.

10条回答
  •  悲&欢浪女
    2021-02-07 12:22

    I also experienced the same issue with Angular 8.2.13 + Typescript. Finally the trick was to use a @Inject('RefOnlyUsedForTesting'), even if the type is string.

    export abstract class MyBaseClass {
      ....
      constructor(@Inject(ElementRef) elementRef: ElementRef,
              @Optional() @Inject('RefOnlyUsedForTesting') dep1: MyObject,
              @Optional() @Inject('RefOnlyUsedForTesting') dep2: string,
              @Optional() @Inject('RefOnlyUsedForTesting') dep3: string) {
      super();    
      ...
     }
    }
    

提交回复
热议问题