ModalCmp ionViewPreLoad error: No provider for AppVersion!


#1

Not sure what I’m missing and I can’t find any examples or documentation. I am creating an about page and trying to use the AppVersion plugin to display the version in a modal dialog. I’m seeing this error both in Chrome and in the Android device emulator. I don’t see any errors in the build. Any ideas on what I might be missing?

Followed plugin installation instructions on http://ionicframework.com/docs/native/app-version/

app.modules.ts

import { AppVersion } from '@ionic-native/app-version';

about-page.ts

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { AppVersion } from '@ionic-native/app-version';

@Component({
  selector: 'page-about',
  templateUrl: 'about-page.html'
})
export class AboutPage {
  private strAppVersion: string;
  constructor(public navCtrl: NavController, 
    public navParams: NavParams,
    private appVersion: AppVersion) {

    }

  ionViewDidLoad() {
    console.log('ionViewDidLoad AboutPage');
    this.appVersion.getVersionCode().then((v) => {
      this.strAppVersion = v;
    });
  }
}

about-page.html

<ion-header>

  <ion-navbar>
    <ion-title>About</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>
  Application version {{this.strAppVersion}}
</ion-content>

Error Message

ModalCmp ionViewPreLoad error: No provider for AppVersion! main.js:6395
ViewController._lifecycle main.js:6395
ViewController._preLoad main.js:6248
NavControllerBase._preLoad main.js:46505
NavControllerBase._viewInit main.js:46146
NavControllerBase._nextTrns main.js:45956
NavControllerBase._queueTrns main.js:45913
NavControllerBase.insertPages main.js:45715
App.present main.js:7521
Modal.present main.js:94498
HomePage.showAboutPage main.js:87084
(anonymous function) main.js:87034
(anonymous function) main.js:104254
Events.publish main.js:104253
MyApp.showAboutPage main.js:141037
View_MyApp0.handleEvent_40 /AppModule/MyApp/component.ngfactory.js:744
(anonymous function) main.js:137532
(anonymous function) main.js:59542
t.invokeTask polyfills.js:3
inner.inner.fork.onInvokeTask main.js:39054
t.invokeTask polyfills.js:3
e.runTask polyfills.js:3
invoke

Versions

Cordova CLI: 6.5.0
Ionic Framework Version: 2.3.0
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.1.4
OS: Windows 10
Node Version: v6.3.0
cordova-plugin-app-version 0.1.9

#2

Did you read the manual?
http://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module


#3

Thank you, I didn’t see that page. I was missing the addition of the plugin to the Providers section of app.module.ts


#4

I am getting this error, but cannot seem to find the error of my ways.

Error: No provider for AppVersion!

I have:

settings.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { SettingsPage } from './settings';

@NgModule({
  declarations: [SettingsPage],
  imports: [IonicPageModule.forChild(SettingsPage)],
})
export class SettingsPageModule { }

settings.ts

import { AppVersion } from '@ionic-native/app-version';

constructor( public appVersion: AppVersion)

#5

Needed to add AppVersion to the settings.module.ts:

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { SettingsPage } from './settings';
import { AppVersion } from '@ionic-native/app-version';

@NgModule({
  declarations: [SettingsPage],
  imports: [IonicPageModule.forChild(SettingsPage)],
  providers: [AppVersion]
})
export class SettingsPageModule { }

#6

Not that it matters much with something like AppVersion, but that’s going to give you a non-singleton. Adding AppVersion as a provider in the main app module didn’t work?