Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(component): default controllerAs to be $ctrl
Closes #13664
Closes #13710
  • Loading branch information
Shahar Talmi authored and petebacondarwin committed Jan 8, 2016
1 parent f31c5a3 commit d91cf16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/ng/compile.js
Expand Up @@ -942,7 +942,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
* registered controller} if passed as a string. An empty `noop` function by default.
* - `controllerAs` – `{string=}` – identifier name for to reference the controller in the component's scope.
* If present, the controller will be published to scope under the `controllerAs` name.
* If not present, this will default to be the same as the component name.
* If not present, this will default to be `$ctrl`.
* - `template` – `{string=|function()=}` – html template as a string or a function that
* returns an html template as a string which should be used as the contents of this component.
* Empty string by default.
Expand Down Expand Up @@ -988,14 +988,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
* ```js
* var myMod = angular.module(...);
* myMod.component('myComp', {
* template: '<div>My name is {{myComp.name}}</div>',
* template: '<div>My name is {{$ctrl.name}}</div>',
* controller: function() {
* this.name = 'shahar';
* }
* });
*
* myMod.component('myComp', {
* template: '<div>My name is {{myComp.name}}</div>',
* template: '<div>My name is {{$ctrl.name}}</div>',
* bindings: {name: '@'}
* });
*
Expand Down Expand Up @@ -1066,7 +1066,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
var template = (!options.template && !options.templateUrl ? '' : options.template);
return {
controller: options.controller || function() {},
controllerAs: identifierForController(options.controller) || options.controllerAs || name,
controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',
template: makeInjectable(template),
templateUrl: makeInjectable(options.templateUrl),
transclude: options.transclude,
Expand Down
2 changes: 1 addition & 1 deletion test/ng/compileSpec.js
Expand Up @@ -9333,7 +9333,7 @@ describe('$compile', function() {
inject(function(myComponentDirective) {
expect(myComponentDirective[0]).toEqual(jasmine.objectContaining({
controller: jasmine.any(Function),
controllerAs: 'myComponent',
controllerAs: '$ctrl',
template: '',
templateUrl: undefined,
transclude: undefined,
Expand Down

0 comments on commit d91cf16

Please sign in to comment.