Runtime Error Error: 0: 0 Caused by: No provider for StatusBar

I am building my application for ionic 2 and I am getting this error:

Runtime Error
Error in :0:0 caused by: No provider for StatusBar!

      

in app.component.ts, I have:

import { StatusBar } from '@ionic-native/status-bar';
...
@Component({
    templateUrl: 'app.html'
})
export class MyApp {

    pageComponent: any;
    private admobid: any;

    constructor(
          public platform: Platform
        , public statusBar: StatusBar
        ...

      

I don't understand if I should list all native plugins in app.module.ts?

+3


source to share


1 answer


As the error shows, you don't have a StatusBar provider.

Add a provider to your component,

@Component({
   .....
   providers: [StatusBar]
})

      



or preferably in your NgModule

@NgModule({
   imports: ...
    .......,
   providers: [StatusBar]
})

      

In the latter case, you will have to add another es6 "import" statement to allow the StatusBar type to be available to add as a provider to the NgModule

+6


source







All Articles