Ale*_*lov 28 javascript typescript angular
在我的Angular2应用程序中收到以下错误错误:(SystemJS)模块'AppModule'声明的意外值'ReleasesService'.请添加@ Pipe/@ Directive/@ Component注释.
我的AppModule:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { routing } from './app.routes';
import { HttpModule } from '@angular/http';
import { SearchFilter } from '../app/search-filter.pipe';
import { ReleasesService } from '../app/releases/releases.service';
import { AppComponent } from './app.component';
import { HomeComponent } from '../app/home/home.component';
import { ReleasesComponent } from '../app/releases/releases.component';
import { DistroComponent } from '../app/distro/distro.component';
import { ContactComponent } from '../app/contact/contact.component';
@NgModule({
imports: [ BrowserModule, HttpModule, routing ],
declarations: [ AppComponent,
SearchFilter,
HomeComponent,
ReleasesComponent,
ReleasesService,
DistroComponent,
ContactComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
我的发布服务:
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { IRelease } from './release';
import 'rxjs/add/operator/map';
@Injectable()
export class ReleasesService {
getReleases() {
return IRelease;
}
}
Run Code Online (Sandbox Code Playgroud)
怎么解决?我重新安装了Quickstarter(我的App的基础),并在尝试创建服务时遇到了同样的错误.
yur*_*zui 41
declarations仅适用于可声明的类:组件指令和管道
您可以添加ReleasesService到providers阵列
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
providers: [ ReleasesService ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
也可以看看
| 归档时间: |
|
| 查看次数: |
26086 次 |
| 最近记录: |