I am new to Ionic 2 and am trying to get through any of the tutorials online that show how to add a provider. It seems that Ionic has changed the app structure the is generated. can some please give me an example of how to do this with the current Ionic 2 app structure? Everywhere I try to import and add my provider to the page class (Constructor and @Component page decorator), I get an error that it cannot be found. All I am trying to do is follow this tutorial with the current Ionic 2 app structure.
In `app.module.ts'
import { PeopleService } from '../providers/people-service';
@NgModule({
declarations: [
// Declarations commented out for brevity
],
imports: [
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
// Entry Components commented out for brevity
],
providers: [PeopleService] // Add PeopleService provider
})
and then on 'home-page.ts'
import {PeopleService} from '../providers/people-service/people-service';
export class HomePage {
public people: any;
constructor(public peopleService: PeopleService){
}
}
You could add a provider by running
> ionic g provider storage-provider
This will generate a ready template
And then add this using import to your app.modules.ts file
> import { StorageProvider } from '../providers/storage-provider';
> import { IonicApp, IonicModule } from 'ionic-angular';
And then in the same app.modules.ts file, you go to the providers section at the very bottom in the file Add the StorageProvider class
providers: [AuthProvider, UtilProvider,**StorageProvider** ],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With