This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($controller): throw error when requested controller is not regis… #15015
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@ngdoc error | ||
@name $controller:ctrlreg | ||
@fullName A controller with this name is not registered. | ||
@description | ||
|
||
This error occurs when the {@link ng.$controller `$controller()`} service is called | ||
with a string that does not match any of the registered controllers. The controller service may have | ||
been invoked directly, or indirectly through the {@link ng.ngController `ngController`} directive, | ||
or when inside a {@link angular.Module#component component} / {@link angular.Module#directive directive} | ||
definition (when using string notation for the controller property). | ||
|
||
Sources for this error can be: | ||
|
||
1. You have a typo in the {@link ng.ngController `ngController`} directive, | ||
in a {@link angular.Module#component component} / {@link angular.Module#directive directive} | ||
definition's controller property, or in the call to {@link ng.$controller `$controller()`}. | ||
2. You have not registered the controller (neither via {@link angular.Module#controller `Module.controller`} | ||
nor {@link ng.$controllerProvider#register `$controllerProvider.register()`}. | ||
3. You have a typo in the *registered* controller name. | ||
4. You want to use controllers defined on the `window`, but have turned off | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would mention that this feature is deprecated/not recommened. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think then it's better to remove this point completely. |
||
{@link ng.$controllerProvider#allowGlobals `allowGlobals()`}. | ||
|
||
|
||
Please consult the {@link ng.$controller $controller} service api docs to learn more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,6 +161,12 @@ describe('$controller', function() { | |
}).toThrow(); | ||
})); | ||
|
||
it('should throw ctrlreg when the controller name does not match a registered controller', inject(function($compile, $rootScope) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused injections. |
||
expect(function() { | ||
$controller('IDoNotExist', {$scope: {}}); | ||
}).toThrowMinErr('$controller', 'ctrlreg', 'The controller with the name \'IDoNotExist\' is not registered.'); | ||
})); | ||
|
||
|
||
describe('ctrl as syntax', function() { | ||
|
||
|
@@ -227,7 +233,6 @@ describe('$controller', function() { | |
'Must match `__name__ as __id__` or `__name__`.'); | ||
}); | ||
|
||
|
||
it('should allow identifiers containing `$`', function() { | ||
var scope = {}; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add "for example through...", because the list is non-exhaustive.
(E.g. a route definitions for
ngRoute
orui.router
and possiblyngMaterial
instantiate controllers as well under the hood.)