角度注入误差。 NulInjectorError:StaticInjectorError(AppModule)[CartPage-> TabsPage]

时间:2020-01-31 04:26:37

标签: angular

以下代码

constructor (
   *private tab: TabsPage,*  //here is NulInjectorError
   private router: Router,
) {
 ////E.G. 
//if( TabsPage != NULL) {    
//   inject
//} else {
 //  ...
 //}
}

可以动态注入吗?
可以吗?
应该怎么办?

1 个答案:

答案 0 :(得分:0)

是的,您可以动态注入。试试这个:-

     tabInstance: Tabspage;
      constructor(private injector: Injector){} // create instance of injector
      someMethod(){
         this.tabInstance = this.injector.get(TabsPage); // you can get the instance of TabsPage in whichever method it's required
       }
相关问题