一直在阅读 Angular 教程并意识到 : 用于类型声明,而 = 用于值分配。看下面的代码export class HeroesComponent implements OnInit { hero: Hero = { id: 1, name: 'Windstorm' }我不明白为什么 id 和 name 使用 : 而不是 = 因为类型已经声明并且我们正在为 hero 的属性分配一个值。export class HeroesComponent implements OnInit { hero: Hero = { id = 1, name = 'Windstorm' }以上是我希望工作但不正确的代码。
添加回答
举报
0/150
提交
取消