Помогите пожалуйста заменить стрелочную функцию обычной
Есть такой сервис:
export var HEROES: Hero[] = [
{ "id": 11, "name": "Mr. Nice" },
{ "id": 12, "name": "Narco" },
{ "id": 13, "name": "Bombasto" },
{ "id": 14, "name": "Celeritas" },
{ "id": 15, "name": "Magneta" },
{ "id": 16, "name": "RubberMan" },
{ "id": 17, "name": "Dynama" },
{ "id": 18, "name": "Dr IQ" },
{ "id": 19, "name": "Magma" },
{ "id": 20, "name": "Tornado" }
];
@Injectable()
export class HeroService {
getHeroes() {
return Promise.resolve(HEROES);
}
}
Так он работает:
export class AppComponent implements OnInit {
ngOnInit() {
this.getHeroes();
}
constructor(private _heroService: HeroService) { }
heroes: Hero[];
title = 'Tour of Heroes';
selectedHero: Hero;
onSelect(hero: Hero) { this.selectedHero = hero; }
getHeroes() {
this._heroService.getHeroes().then(heroes => this.heroes = heroes);
}
}
А так не работает:
export class AppComponent implements OnInit {
ngOnInit() {
this.getHeroes();
}
constructor(private _heroService: HeroService) { }
heroes: Hero[];
title = 'Tour of Heroes';
selectedHero: Hero;
onSelect(hero: Hero) { this.selectedHero = hero; }
getHeroes() {
this._heroService.getHeroes().then( function(heroes) {
this.heroes = heroes;
});
}
}