2017-10-04 102 views
0

我只是运行一个如何构建离子应用程序的例子。然而,当我所服务的应用程序,我得到这个错误,没有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的

+0

当使用一个服务,一个'@ ngModule'必须导入{...}从'...'然后列在提供者下:[...]' –

+0

你的UrlHelperService在哪里? – Melchia

+0

@Melchia UrlHelperService包含在OAuthService中我认为 – jamesim

回答

1

这个错误出现在你使用的是一些服务(在你的情况UrlHelperService)在您的应用程序,但还没有把它添加到providers

确保当您创建和在应用程序中使用任何服务,您必须将它们导入providers@NgModule

import { SomeService } from "../services/some-service.service"; 

@NgModule({ 
     declarations: [ // Components ], 
     imports: [ // Modules ], 
     bootstrap: [IonicApp], 
     entryComponents: [// Entry Components], 
     providers: [ SomeService ] // <==== HERE 
}) 
export class AppModule {} 
+0

哇,这是显而易见的....感谢 – jamesim