事件component.ts
EventService 是服务类 Injectable ,但我收到错误[ts]无法找到模块'/shared/event.service',但 app.module.ts 我正在为这项服务提供相同的途径。路径是正确的请告诉我这是错的..
import { Component } from '@angular/core'
import { EventService } from '/shared/event.service'
//[ts] Cannot find module '/shared/event.service'.
@Component({
selector: 'event-list',
template: `<div><h2>we are using Angular Js 2</h2><hr/>
<div class="row">
<div class="col-md-6" *ngFor="let event of events">
<event-thumbnil [eventList] = "event" >
</event-thumbnil>
</div>
</div>
</div>`
})
export class EventsListComponent {
events:any[]
constructor(private eventService : EventService)
{
this.events= this.eventService.getEvents();
}
}
app.module.ts
import { NgModule } from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {EventsAppComponent } from './events-app.component'
import { EventsListComponent } from './Events/events-list.component'
import {EventThumbnilComponent } from './Events/events-list.thumbnil'
import {NavabarComponent} from './nav/navbar-component'
import {EventService} from './shared/event.service'
@NgModule({
imports:[BrowserModule],
declarations: [EventsAppComponent, EventsListComponent,EventThumbnilComponent,NavabarComponent],
bootstrap:[EventsAppComponent],
providers:[EventService]
})
export class AppModule{
}
答案 0 :(得分:1)
import {EventService} from '../shared/event.service'
检查它可能有效