toddmotto / angular-component

Fully featured .component() polyfill for Angular v1.3+
https://toddmotto.com
Other
191 stars 30 forks source link

controllerAs name VS '$ctrl' #13

Closed mrichard closed 8 years ago

mrichard commented 8 years ago

First thanks for putting this together.

One issue, should the controllerAs property setting reference name in the last OR clause? Instead of '$ctrl'.

toddmotto commented 8 years ago

Hey, I'm not 100% sure what you mean. It sets $ctrl as the default, but you can set your own using something like:

{
  ...
  controller: 'MyDirectiveController as name'
  ...
}

And then ng-click="name.foo()" for example in the templates.

mrichard commented 8 years ago

Not sure if this is the latest code, but here the default is the name parameter passed into the component definition.

https://github.com/angular/angular.js/blob/54e816552f20e198e14f849cdb2379fed8570c1a/src/loader.js#L377

toddmotto commented 8 years ago

Yep this is from October 2015, check this source: https://code.angularjs.org/1.5.0/angular.js

Search for this.component = function registerComponent(name, options) {

And then this piece:

controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',