I am following the https://angular.io/tutorial/toh-pt2 tutorial to learn about angular. And apparently if the "Hero" class and "const HEROES" array are not above the "@Component" section, the application does not work. Any reason behind this? Is there a structure that needs to be followed?
0
votes
1 Answers
0
votes
Javascript is parsed top to bottom. So when the constant HERORES
or the class Hero
is referenced inside the component, they must already be known to the Javascript engine. Otherwise it does not recognize them and throws an error.
// ok
var name = 'Anna';
console.log(name);
// error: what's 'name'?
console.log(name);
var name = 'Anna'
it's not an Angular specific issue.