Angular Error : StaticInjectorError (Platform: core)[e -> t]:

后端 未结 2 712
有刺的猬
有刺的猬 2021-01-20 17:18

As I am build the APK with --prod I am getting the error below

    ERROR Error: StaticInjectorError[e -> t]: 
  StaticInjectorError(Platform:         


        
2条回答
  •  旧巷少年郎
    2021-01-20 18:02

    You are trying to use a service that is not listed in providers of your AppModule or inside you component.ts. Add the service to a providers list to make it work.

    In app.modules if you want that service to be global (related to app context).

    @NgModule({
        declarations: [...],
        imports: [...],
        bootstrap: [...],
        entryComponents: [...],
        providers: [
            MyService
        ]
    })
    

    Or in your component.ts if you want that service to be contextual to desired component.

    @Component({
        selector: '...',
        templateUrl: '...',
        providers: [MyService]
    })
    

    Do not add it in both files. Also don't forget to import that service when you inject it either in app.modules or component.

    import { MyService } from '../services/myservice';
    

    This question also may help you: Error: No provider for t

提交回复
热议问题