Bootstraping全球服务的问题

时间:2016-12-26 17:36:08

标签: angular nativescript

我有一个名为DataService的SharedService。我试图把它变成Singleton。 所以我尝试在我的app.module.ts中引导这个

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

当我跑步时,它会让我异常

Component DataService不是任何NgModule的一部分,或者模块尚未导入您的模块。

请帮助!!!!

1 个答案:

答案 0 :(得分:1)

错误消息指出Angular认为DataService是一个组件,因为您具有模块的bootstrap属性。

  1. 从引导程序中删除[DataService]
  2. 取消注释提供商行
  3. 确保在文件passenger-list.services
  4. 中导出DataService
相关问题