SamVerschueren / angular2-polyfill

Angular2 polyfill for Angular1
MIT License
29 stars 3 forks source link

`controllerAs` value #10

Closed SamVerschueren closed 8 years ago

SamVerschueren commented 8 years ago

At the moment, the controllerAs value is the camelcase variant of the component selector. For instance, if the selector is my-heroes, the controllerAs value is myHeroes.

When I decided that, it looked like a good suggestion, but is it? I noticed that when refactoring, and changing the selector of the component, it always ends up in a find-and-replace in the view.

Angular 1.5 uses $ctrl in the view to refer to the controller. The benefit is that it doesn't change when the selector changes. Any other ideas for this?

Ledragon commented 8 years ago

I personnally always use controllerAs: vm in all my current (angular 1.4) directives. I think it makes it easier to use a consistent name when writing the view, as I don't have to remember what the name is when writing the view.

SamVerschueren commented 8 years ago

Where does vm stand for? Think I might go with ctrl, just like Angular 1.5. Seems also like the best option in terms of upgrading an Angular 1.5 application to use Angular2-polyfill. It won't force the user to change the templates because the reference to the controller is the same as it was before (in Angular 1.5).

Ledragon commented 8 years ago

vm stands for viewModel. I took it from here. But indeed using ctrl or even $ctrl to be consistent with angular 1.5 seems to be a better choce atm.