Following the tutorial Iangular2
found this code google
snippet:
export class AppComponent {
title = 'Tour of Heroes';
heroes = HEROES;
selectedHero: Hero;
onSelect(hero: Hero) { this.selectedHero = hero; }
}
I transcribed this code in my editor and I got an error. It was simply that it had selectedHero = Hero;
instead of selectedHero: Hero;
, but for me the most natural thing is that they all be with =
as well as title and heroes .
When should the symbol be used =
and when :
when adding properties to a component?
The full syntax in typescript is:
So they are different pieces of the same syntax.
What goes after the colon
:
is the data type, what goes after the equal sign=
is the initial value of the variable.In this example, the data types are inferred by typescript.