0

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!!!!

  • Possible duplicate of [Angular 2 Component is not part of any NgModule](http://stackoverflow.com/questions/39527722/angular-2-component-is-not-part-of-any-ngmodule) – SeleM Dec 26 '16 at 19:04
  • It is not duplicate – Rajiv Krishnaa Dec 26 '16 at 19:26
  • Follow the steps provided by Yakov Fain below and meanwhile, you can take a look at this example to see how to use service as providers https://github.com/NativeScript/nativescript-sdk-examples-ng/blob/d978f0beae3f16198f57be2fbd4138cd35cd2d51/app/http/http-post/http-post.component.ts#L8 – Nick Iliev Dec 27 '16 at 10:36

1 Answers1

1

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
Yakov Fain
  • 11,972
  • 5
  • 33
  • 38