Ionic 2 Provider

I am new to Ionic 2 and I am trying to go through any of the online tutorials that show how to add a provider. Ionic seems to have changed the structure of the application generated. can someone please give me an example of how to do this with the current structure of Ionic 2 applications? Everywhere where I try to import and add my provider to the page class (constructor and constructor of the @Component page), I get an error that cannot be found. All I'm trying to do is follow this tutorial with the current structure of Ionic 2 applications.

+4
source share
3 answers

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
})

'home-page.ts'

import {PeopleService} from '../providers/people-service/people-service';

export class HomePage {
public people: any;

    constructor(public peopleService: PeopleService){

      }
    }
+5

,

> ionic g provider storage-provider

, , app.modules.ts

> import { StorageProvider } from '../providers/storage-provider';
> import { IonicApp, IonicModule  } from 'ionic-angular';

app.modules.ts StorageProvider

providers: [AuthProvider,  UtilProvider,**StorageProvider**  ],
+5

2 , , - , .

Angular 2 - , , , .

github repository , , : https://github.com/driftyco/ionic2-starter-tabs, .

+2

Source: https://habr.com/ru/post/1662569/


All Articles