Hello guys,
since I tried to use a provider, I have the following problem: I get the Runtime Error "Cannot find module “…/provider/global/global”, but the path is correct. I think my code is missing something like an import, but also after searching the entire web I can not find the problem.
This is my code:
Provider:
global.ts
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class GlobalProvider {
public globalcount: number = 666;
constructor(public http: HttpClient) {
console.log('Hello GlobalProvider Provider');
}
}
app.component.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { CentralPage } from '../pages/central/central';
import { GlobalProvider } from '../providers/global/global';
import * as math from 'mathjs';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = CentralPage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
});
}
}
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { CentralPage } from '../pages/central/central';
import { GlobalProvider } from '../providers/global/global';
@NgModule({
declarations: [
MyApp,
CentralPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
CentralPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
GlobProvider
]
})
export class AppModule {}
and the page where I want to access the variable:
central.ts:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AlertController } from 'ionic-angular';
import { GlobalProvider } from '../providers/global/global';
@Component({
selector: 'page-central',
templateUrl: 'central.html',
})
export class CentralPage {
constructor(public navCtrl: NavController, public alertCtrl: AlertController, public global: GlobalProvider) {}
globaltest(){
console.log(JSON.stringify(global.globalcount));
}
}
If you have any ideas what my problem is, I would be very thankfully for help.
Greetings,
Robert