2016-12-26 28 views
0

我有称为DataService的SharedService。我试图把它作为Singleton。 于是,我就当我运行来引导这在我app.module.ts这样Bootstraping全局服务的问题

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 { } 

,它扔我异常

组件的DataService没有任何NgModule的部分或模块尚未导入你的模块。

请帮忙!!!!

+0

[角2分量的可能的复制是不部分任何NgModule](http://stackoverflow.com/questions/39527722/angular-2-component-is-not-part-of-any-ngmodule) –

+0

它不重复 –

+0

请按照以下步骤提供的Yakov Fain同时,你可以看看这个例子来看看如何使用你se服务作为提供者https://github.com/NativeScript/nativescript-sdk-examples-ng/blob/d978f0beae3f16198f57be2fbd4138cd35cd2d51/app/http/http-post/http-post.component.ts#L8 –

回答

1

错误消息指出Angular相信DataService是一个组件,因为您在模块的引导属性中。

  1. 从引导
  2. 取消对提供商行中删除[DataService的]
  3. 确保您在文件中导出的DataService passenger-list.services