我正在使用Angular基础知识的复数教程。
我认为我的错误与此代码有关:
import { Component, OnInit} from '@angular/core';
import { EventService } from "./shared/event.service";
import { ToastrService } from '../common/toastr.service'
import { ActivatedRoute } from "@angular/router";
@Component({
selector:'events-list',
template:`
<div>
<h1> Upcoming Angular 2 Events </h1>
<hr/>
<div class="row">
<div *ngFor="let event of events" class="col-md-5">
<event-thumbnail (click)="handleThumbnailClick(event.name)" [event] = "event"> </event-thumbnail>
</div>
</div>
</div>
`
})
export class EventListComponent implements OnInit{
events:any
constructor(private eventService:EventService, private toastr:ToastrService, private route:ActivatedRoute) {
}
ngOnInit() {
this.events = this.route.snapshot.data['events']
}
handleThumbnailClick(eventName)
{
this.toastr.success(eventName)
}
}
我尝试使用事件:任何[]但是有一个相同的错误。 我甚至尝试使用我的ngOnInit()方法,例如this.route.snapshot.data ['events'],而不使用this.events
答案 0 :(得分:0)
初始化events数组并确保 this.route.snapshot.data['events']
返回一个数组,
events:any = [];