我只是運行一個如何構建離子應用程序的例子。然而,當我所服務的應用程序,我得到這個錯誤,沒有UrlHelperService的提供商
Error: No provider for UrlHelperService!
at injectionError (http://localhost:8100/build/vendor.js:1527:90)
at noProviderError (http://localhost:8100/build/vendor.js:1565:12)
at ReflectiveInjector_._throwOrNull (http://localhost:8100/build/vendor.js:3007:19)
at ReflectiveInjector_._getByKeyDefault (http://localhost:8100/build/vendor.js:3046:25)
at ReflectiveInjector_._getByKey (http://localhost:8100/build/vendor.js:2978:25)
at ReflectiveInjector_.get (http://localhost:8100/build/vendor.js:2847:21)
at resolveNgModuleDep (http://localhost:8100/build/vendor.js:9847:25)
at _createClass (http://localhost:8100/build/vendor.js:9898:32)
at _createProviderInstance$1 (http://localhost:8100/build/vendor.js:9858:26)
at resolveNgModuleDep (http://localhost:8100/build/vendor.js:9843:17)
我app.module.ts
import { NgModule, ErrorHandler } from '@angular/core';
import {HttpModule} from '@angular/http';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import {LoginPage} from "../pages/login/login";
import {OAuthService} from "angular-oauth2-oidc";
@NgModule({
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
LoginPage
],
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
LoginPage ],
providers: [
OAuthService,
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
我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 { TabsPage } from '../pages/tabs/tabs';
import { OAuthService } from 'angular-oauth2-oidc';
import { LoginPage } from '../pages/login/login';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = TabsPage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen:
SplashScreen, oauthService: OAuthService) {
if (oauthService.hasValidIdToken()) {
this.rootPage = TabsPage;
} else {
this.rootPage = LoginPage;
}
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
});
}
}
我使用 離子框架:3.7.0 Ionic App腳本:3.0.0 Angular Core:4.4.3 Angular Compiler CLI:4.4.3 節點:6.11。 0 OS平臺:視窗10 導航平臺:Win32的
當使用一個服務,一個'@ ngModule'必須導入{...}從'...'然後列在提供者下:[...]' –
你的UrlHelperService在哪裏? – Melchia
@Melchia UrlHelperService包含在OAuthService中我認爲 – jamesim