即使我在导入

时间:2017-07-01 05:07:02

标签: angularjs git visual-studio-code

事件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{

}

1 个答案:

答案 0 :(得分:1)

在你的打字稿文件中,你忘了给你服务的目录

import {EventService} from '../shared/event.service'

检查它可能有效