view raw
Niall Niall - 9 months ago 70
AngularJS Question

What does this mean from the angular2 documentation?

I am currently learning Angular2 and typescript and this part of the angular 2 documentation is causing a problem. Could someone give an explanation of => in the context of how it is used in the example below? I searched online and found references to lambda functions and return types but I couldn't find anything that matched the use of => like it is used here.

export class DashboardComponent implements OnInit {
heroes: Hero[] = [];
constructor(private heroService: HeroService) { }
ngOnInit() {
.then(heroes => this.heroes = heroes.slice(1, 5));
gotoDetail() { /* not implemented yet */}

If anyone can help me understand this I would really appreciate it.



 .then(heroes => this.heroes = heroes.slice(1, 5));

is equivalent of:

var that = this;
 .then(function (heroes) {
     return that.heroes = heroes.slice(1, 5));