我在app.moudule.ts離子2運行時錯誤無Porvider
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { HttpModule } from '@angular/http';
import { MyApp } from './app.component';
import { IonicStorageModule } from '@ionic/storage';
import { InfiniteScrollModule } from 'angular2-infinite-scroll';
import { LoginPage } from '../pages/login/login';
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 { AuthServiceProvider } from '../providers/auth-service/auth-service';
import { JobsServiceProvider } from '../providers/jobs-service/jobs-service';
import { DataListProvider } from '../providers/data-list/data-list';
@NgModule({
declarations: [
MyApp,
LoginPage,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot(),
InfiniteScrollModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
LoginPage,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
JobsServiceProvider,
DataListProvider
]
})
export class AppModule {}
,並在我的文件中創建一個提供程序文件名爲數據list.ts
包括它在這裏我想用它(home.ts),其中包括它在我的構造
import { DataListProvider } from '../../providers/data-list/data-list';
constructor(public navCtrl: NavController,public DataListProvider: DataListProvider) {}
,但我不斷收到這個錯誤,我缺少什麼:
MyApp_Host.html:1 ERROR Error: No provider for DataListProvider! at injectionError (core.es5.js:1231) at noProviderError (core.es5.js:1269) at ReflectiveInjector_.throwOrNull (core.es5.js:2770) at ReflectiveInjector.getByKeyDefault (core.es5.js:2809) at ReflectiveInjector.getByKey (core.es5.js:2741) at ReflectiveInjector.get (core.es5.js:2610) at AppModuleInjector.NgModuleInjector.get (core.es5.js:3557) at resolveDep (core.es5.js:11017) at createClass (core.es5.js:10881) at createDirectiveInstance (core.es5.js:10701)
您在服務類DataListProvider中添加了@Injectable()嗎? –
是的,我已經加了 – noor
請更新問題與你的'DataListProvider.ts'代碼 –