Rajiv Krishnaa
Rajiv Krishnaa

Reputation: 99

Issues with Bootstraping global service

I have SharedService called DataService. Im trying to make that as Singleton. So I tried to bootstrap this in my app.module.ts like this

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/platform";
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { NativeScriptHttpModule } from "nativescript-angular/http";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import "reflect-metadata";
import { AppComponent } from "./app.component";
import {ArraysPipe} from "./arraypipe";
import { routes, navigatableComponents } from "./app.routing";
import { DataService } from "./services/passenger-list.services";

@NgModule({
declarations: [AppComponent,ArraysPipe,...navigatableComponents],
//providers:[DataService],
bootstrap: [AppComponent,[DataService]],
imports: [
NativeScriptModule,
NativeScriptFormsModule,
NativeScriptHttpModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(routes)
  ],
schemas: [NO_ERRORS_SCHEMA]
})
export class AppModule { }

When I run , it is throwing me exception

Component DataService is not part of any NgModule or the module has not been imported into your module.

Please help!!!!

Upvotes: 0

Views: 63

Answers (1)

Yakov Fain
Yakov Fain

Reputation: 12376

The error message states that Angular believes that DataService is a component because you have in the bootstrap property of the module.

  1. Remove [DataService] from the bootstrap
  2. Uncomment the providers line
  3. Make sure you export DataService in the file passenger-list.services

Upvotes: 1

Related Questions