Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d91cf16

Browse files
Shahar Talmipetebacondarwin
Shahar Talmi
authored andcommitted
feat(component): default controllerAs to be $ctrl
Closes #13664 Closes #13710
1 parent f31c5a3 commit d91cf16

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/ng/compile.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
942942
* registered controller} if passed as a string. An empty `noop` function by default.
943943
* - `controllerAs` – `{string=}` – identifier name for to reference the controller in the component's scope.
944944
* If present, the controller will be published to scope under the `controllerAs` name.
945-
* If not present, this will default to be the same as the component name.
945+
* If not present, this will default to be `$ctrl`.
946946
* - `template` – `{string=|function()=}` – html template as a string or a function that
947947
* returns an html template as a string which should be used as the contents of this component.
948948
* Empty string by default.
@@ -988,14 +988,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
988988
* ```js
989989
* var myMod = angular.module(...);
990990
* myMod.component('myComp', {
991-
* template: '<div>My name is {{myComp.name}}</div>',
991+
* template: '<div>My name is {{$ctrl.name}}</div>',
992992
* controller: function() {
993993
* this.name = 'shahar';
994994
* }
995995
* });
996996
*
997997
* myMod.component('myComp', {
998-
* template: '<div>My name is {{myComp.name}}</div>',
998+
* template: '<div>My name is {{$ctrl.name}}</div>',
999999
* bindings: {name: '@'}
10001000
* });
10011001
*
@@ -1066,7 +1066,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10661066
var template = (!options.template && !options.templateUrl ? '' : options.template);
10671067
return {
10681068
controller: options.controller || function() {},
1069-
controllerAs: identifierForController(options.controller) || options.controllerAs || name,
1069+
controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',
10701070
template: makeInjectable(template),
10711071
templateUrl: makeInjectable(options.templateUrl),
10721072
transclude: options.transclude,

test/ng/compileSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9333,7 +9333,7 @@ describe('$compile', function() {
93339333
inject(function(myComponentDirective) {
93349334
expect(myComponentDirective[0]).toEqual(jasmine.objectContaining({
93359335
controller: jasmine.any(Function),
9336-
controllerAs: 'myComponent',
9336+
controllerAs: '$ctrl',
93379337
template: '',
93389338
templateUrl: undefined,
93399339
transclude: undefined,

0 commit comments

Comments
 (0)