Angular 从角度文档来看,这意味着什么?
我目前正在学习Angular和typescript,Angular文档的这一部分导致了一个问题。有人能在下面的例子中解释一下Angular 从角度文档来看,这意味着什么?,angular,typescript,Angular,Typescript,我目前正在学习Angular和typescript,Angular文档的这一部分导致了一个问题。有人能在下面的例子中解释一下=>的用法吗?我在网上搜索并找到了lambda函数和返回类型的引用,但找不到任何与=>的用法相匹配的内容,就像这里使用的那样 export class DashboardComponent implements OnInit { heroes: Hero[] = []; constructor(private heroService: HeroService) { } ng
=>
的用法吗?我在网上搜索并找到了lambda函数和返回类型的引用,但找不到任何与=>
的用法相匹配的内容,就像这里使用的那样
export class DashboardComponent implements OnInit {
heroes: Hero[] = [];
constructor(private heroService: HeroService) { }
ngOnInit() {
this.heroService.getHeroes()
.then(heroes => this.heroes = heroes.slice(1, 5));
}
gotoDetail() { /* not implemented yet */}
}
如果有人能帮我理解这一点,我将不胜感激。如下
this.heroService.getHeroes()
.then(heroes => this.heroes = heroes.slice(1, 5));
相当于:
var that = this;
this.heroService.getHeroes()
.then(function (heroes) {
return that.heroes = heroes.slice(1, 5));
});
这称为箭头函数,可以在TypeScript教程中理解 在您的代码中,“getHeroes”函数将返回一些响应,该响应将存储在局部变量“heroes”中 '英雄=>'=函数(英雄:任意) 其余部分可视为功能体。这是一种很好的做法,可以使引用保持活动状态,并保持某些变量的局部性。尝试以下方法: