File tree 5 files changed +46
-2
lines changed
5 files changed +46
-2
lines changed Original file line number Diff line number Diff line change
1
+ @ngdoc error
2
+ @name $controller:ctrlreg
3
+ @fullName A controller with this name is not registered.
4
+ @description
5
+
6
+ This error occurs when the {@link ng.$controller `$controller()`} service is called
7
+ with a string that does not match any of the registered controllers. The controller service may have
8
+ been invoked directly, or indirectly through the {@link ng.ngController `ngController`} directive,
9
+ or when inside a {@link angular.Module#component component} / {@link angular.Module#directive directive}
10
+ definition (when using string notation for the controller property).
11
+
12
+ Sources for this error can be:
13
+
14
+ 1. You have a typo in the {@link ng.ngController `ngController`} directive,
15
+ in a {@link angular.Module#component component} / {@link angular.Module#directive directive}
16
+ definition's controller property, or in the call to {@link ng.$controller `$controller()`}.
17
+ 2. You have not registered the controller (neither via {@link angular.Module#controller `Module.controller`}
18
+ nor {@link ng.$controllerProvider#register `$controllerProvider.register()`}.
19
+ 3. You have a typo in the *registered* controller name.
20
+ 4. You want to use controllers defined on the `window`, but have turned off
21
+ {@link ng.$controllerProvider#allowGlobals `allowGlobals()`}.
22
+
23
+
24
+ Please consult the {@link ng.$controller $controller} service api docs to learn more.
Original file line number Diff line number Diff line change 5
5
6
6
AngularJS often asserts that certain values will be present and truthy using a
7
7
helper function. If the assertion fails, this error is thrown. To fix this problem,
8
- make sure that the value the assertion expects is defined and truthy.
8
+ make sure that the value the assertion expects is defined and matches the type mentioned in the
9
+ error.
Original file line number Diff line number Diff line change @@ -122,6 +122,11 @@ function $ControllerProvider() {
122
122
: getter ( locals . $scope , constructor , true ) ||
123
123
( globals ? getter ( $window , constructor , true ) : undefined ) ;
124
124
125
+ if ( ! expression ) {
126
+ throw $controllerMinErr ( 'ctrlreg' ,
127
+ 'The controller with the name \'{0}\' is not registered.' , constructor ) ;
128
+ }
129
+
125
130
assertArgFn ( expression , constructor , true ) ;
126
131
}
127
132
Original file line number Diff line number Diff line change @@ -161,6 +161,12 @@ describe('$controller', function() {
161
161
} ) . toThrow ( ) ;
162
162
} ) ) ;
163
163
164
+ it ( 'should throw ctrlreg when the controller name does not match a registered controller' , inject ( function ( $compile , $rootScope ) {
165
+ expect ( function ( ) {
166
+ $controller ( 'IDoNotExist' , { $scope : { } } ) ;
167
+ } ) . toThrowMinErr ( '$controller' , 'ctrlreg' , 'The controller with the name \'IDoNotExist\' is not registered.' ) ;
168
+ } ) ) ;
169
+
164
170
165
171
describe ( 'ctrl as syntax' , function ( ) {
166
172
@@ -227,7 +233,6 @@ describe('$controller', function() {
227
233
'Must match `__name__ as __id__` or `__name__`.' ) ;
228
234
} ) ;
229
235
230
-
231
236
it ( 'should allow identifiers containing `$`' , function ( ) {
232
237
var scope = { } ;
233
238
Original file line number Diff line number Diff line change @@ -150,4 +150,13 @@ describe('ngController', function() {
150
150
$httpBackend . flush ( ) ;
151
151
expect ( controllerScope . name ) . toBeUndefined ( ) ;
152
152
} ) ) ;
153
+
154
+ it ( 'should throw ctrlreg when the controller name does not match a registered controller' , inject ( function ( $compile , $rootScope ) {
155
+ element = jqLite ( '<div ng-controller="IDoNotExist"></div>' ) ;
156
+
157
+ expect ( function ( ) {
158
+ element = $compile ( element ) ( $rootScope ) ;
159
+ } ) . toThrowMinErr ( '$controller' , 'ctrlreg' , 'The controller with the name \'IDoNotExist\' is not registered.' ) ;
160
+ } ) ) ;
161
+
153
162
} ) ;
You can’t perform that action at this time.
0 commit comments