I'm learning Angular 2, and I'm confusing with the 'this' keyword. Consider the code below :
import { Component, OnInit } from '@angular/core';
import { Hero } from '../heroes';
import { HEROES } from '../mock-heroes';
@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
selectedHero : Hero;
onSelect(hero : Hero) : void{
this.selectedHero = hero;
}
heroes = HEROES;
constructor() { }
ngOnInit() {
}
}
Here in 'onSelect' method, why we need to use 'this' keyword for referring 'selectedHero' property? Why can't we just use 'selectedHero' without this keyword? And what does 'this' imply here?