export class DashboardComponent implements OnInit {
heroes: Hero[] = [];
constructor(private heroService: HeroService) { }
ngOnInit(): void {
this.heroService.getHeroes()
.then(heroes => this.heroes = heroes.slice(1, 5));
}
}
这里heroes: Hero[] = []改成 heroes: Hero[];为什么无法运行? 区别在哪?
看不到模板,无法分析具体原因。
但,有一点,定义一个变量且初始化,不光是一个好的习惯,更应该形成一种习惯!