嗨,我对 UserService 的值有疑问
问题是我不确定是否需要 providers: [UserService]
所以我试图删除它但没有奏效。
昨天运行良好,没有任何变化,但今天早上停止工作。
我正在使用最新的 Angular2 版本和 Angular-CLI
@angular/core: 2.4.9
@angular/cli: 1.0.0-rc.1
索引.ts
import { NgModule } from '@angular/core';
import { UserService } from './user/user.service';
import { LevelService } from './levels/levels.service';
import { AlertService } from './alert/alert.service';
import { CommentService } from './comments/comments.service';
@NgModule({
declarations: [
UserService,
LevelService,
AlertService,
CommentService
],
providers: [
UserService,
LevelService,
AlertService,
CommentService
]
})
export class Services {
static forRoot() {
return {
ngModule: Services,
providers: [ UserService, LevelService, AlertService, CommentService ]
}
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { UIRouterModule } from "ui-router-ng2";
import { alertaddState } from "./app.states";
import { alertlistState } from "./app.states";
import { dashboardState } from "./app.states";
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { MainComponent } from './modules/main/main.module';
import { AppFooterComponent } from './components/app-footer/app-footer.component';
import { AppHeaderComponent } from './components/app-header/app-header.component';
import { AppSideNavbarComponent } from './components/app-side-navbar/app-side-navbar.component';
import { Services } from './services';
import { DashboardComponent } from './modules/dashboard/dashboard/dashboard.component';
import { LevelslistComponent } from './modules/levels/levelslist/levelslist.component';
import { LevelsaddComponent } from './modules/levels/levelsadd/levelsadd.component';
import { UserlistComponent } from './modules/user/userlist/userlist.component';
import { UseraddComponent } from './modules/user/useradd/useradd.component';
import { AlertlistComponent } from './modules/alert/alertlist/alertlist.component';
import { AlertaddComponent } from './modules/alert/alertadd/alertadd.component';
import { CommentslistComponent } from './modules/comments/commentslist/commentslist.component';
import { CommentsaddComponent } from './modules/comments/commentsadd/commentsadd.component';
import { MyDatePickerModule } from 'mydatepicker';
@NgModule({
declarations: [
MainComponent,
AppFooterComponent,
AppHeaderComponent,
AppSideNavbarComponent,
DashboardComponent,
LevelslistComponent,
LevelsaddComponent,
UseraddComponent,
UserlistComponent,
AlertaddComponent,
AlertlistComponent,
CommentsaddComponent,
CommentslistComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
NgbModule.forRoot(),
UIRouterModule.forRoot(
{ states: [
dashboardState,
alertaddState,
alertlistState
], useHash: false }),
MyDatePickerModule,
Services.forRoot()
],
providers: [],
bootstrap: [MainComponent]
})
export class AppModule { }
知道我做错了什么吗?谢谢
最佳答案
从 index.ts 文件中删除此声明数组。无需添加 declarations
,因为 @Injectable
位于 providers
数组中。
declarations: [
UserService,
LevelService,
AlertService,
CommentService
],
关于angular - 错误 : Unexpected value 'UserService' declared by the module 'Services' at SyntaxError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42807959/