angular 官网中订阅服务的语法谁能解释一下?
在hero.component中 我们定义了一个函数来获取hero.service的请求
getHeroes(): void {
this.heroService.getHeroes()
.subscribe(heroes => this.heroes = heroes);
}
我知道 this.heroes是该component中的变量
那么 heroes 是一个异步返回后的数组吗?
为什么是 heroes => this.heroes = heroes
而不是 heroes => this.heroes
这里的等号是什么意思?
=> 是es6中的箭头函数, 与普通函数不同的是它可以绑定当前上下文
详见 https://developer.mozilla.org...
分解开等同于