I have created a test provider and I am attempting to inject it into two pages for the purpose of sharing data and methods. However, when I add the provider to the page constructor, an error is thrown, stating "Can't resolve all parameters for CharacterPage: (NavController, NavParams, ?)".
Ionic Framework: 2.0.1
Ionic Native: 2.4.1
Ionic App Scripts: 1.1.0
Angular Core: 2.2.1
Angular Compiler CLI: 2.2.1
Node: 6.9.4
OS Platform: Windows 10
Navigator Platform: Win32
app.module.ts
import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { MyApp } from './app.component';
import { BookNavigation } from '../providers/book-navigation';
@NgModule({
declarations: [ //STUFF ],
imports: [ IonicModule.forRoot(MyApp) ],
bootstrap: [IonicApp],
entryComponents: [ //STUFF ],
providers: [
{
provide: ErrorHandler,
useClass: IonicErrorHandler,
},
Storage,
BookNavigation,
]
})
export class AppModule {}
app.components.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { BookNavigation } from '../providers/book-navigation';
import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html',
providers: [BookNavigation]
})
export class MyApp {
rootPage = HomePage;
constructor(platform: Platform) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
});
}
characterPage.ts
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { BookNavigation } from '../../providers/book-navigation';
@Component({
selector: 'page-character',
templateUrl: 'page.html'
})
export class CharacterPage {
constructor(public navCtrl: NavController,
public navParams: NavParams,
public bookNavigation: BookNavigation) {}
}
Service Provider
import { Injectable } from '@angular/core';
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Storage } from '@ionic/storage';
@Injectable()
export class BookNavigation {
constructor(public navCtrl: NavController, public navParams: NavParams, public storage:Storage) {
console.log('Hello BookNavigation Provider');
}
}