Error: Uncaught (in promise): Error: No provider for


#1

Im Create new Ionic page name for listing and i m added some file its name listing.service.ts after I cant open this listing page i had some error

Error: Uncaught (in promise): Error: No provider for ListingService!
Error: No provider for ListingService!

Im try to fix it for more than one hour but cant found any solutions , how to fix it ? Thanks This is my code

listing.module.ts


import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ListingPage } from './listing';
import  {ListingService} from "./listing.service";


@NgModule({
  declarations: [
    ListingPage,
  ],
  imports: [
    IonicPageModule.forChild(ListingPage),
  ],
  providers: [
    ListingService
  ]
})
export class ListingPageModule {}

listing.service.ts

import {Injectable} from '@angular/core';
 @Injectable()
    export class ListingService {
      private eventMap:any;
      constructor() {
        this.initEventMap();
      }

app.module.ts

import {ListingService} from "../pages/listing/listing.service";

const providers = [ ListingService ];

@NgModule({
  declarations: [
    MyApp,
    HomePage




  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    CalendarModule, // Ionic Calendar

  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage

  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

#2

Hi,

Please add ListingService into app.module.ts. Because the ionic application will manage the class throughout app.module.ts. You can not change it to listing.module.ts.

Please take a look your main.ts like this

import {enableProdMode} from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

It is pointing to app.module.ts. If you want to change default class to manage the application. Please change AppModule here to your class (listing.module.ts).

Thanks ,


#3

Thanks sir, its working fine