3
ng-controller="StoreController as store"

instead of

ng-controller="StoreController"

What is the difference?

Dave
  • 1,428
  • 4
  • 31
  • 49

2 Answers2

2

Please refer to this link as to know why they add an alias or specifically a scope for Angular. It's more of a clearer namespaces vs confusing namespaces

Community
  • 1
  • 1
Cedric
  • 1,236
  • 2
  • 18
  • 35
1

Additionally, an alias is like an instance in POO. By doing this you are sure to be accessing only the StoreController scope in you code.

You can get controllers(child) which are shadowed in another controller(parent) with the same scope 'id'. Doing this {{ id }} will display the id of the parent.

Using an alias this becomes

controllers(child) as child
controller(parent) as parent

and child.id gives the id of the child and parent.id displays the id of the parent.

Hope this helps

Kwaye Kant
  • 47
  • 1
  • 6