forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix($controller): throw better error when controller expression is bad
Previously, the error was a JS runtime error when trying to access a property of `null`. But, it's a bit nicer to throw a real error and provide a description of how to fix it. Developer ergonomics and all that. Closes angular#10875 Closes angular#10910
- Loading branch information
Showing
3 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,46 @@ | ||
@ngdoc error | ||
@name $controller:ctrlfmt | ||
@fullName Badly formed controller string | ||
@description | ||
|
||
This error occurs when {@link ng.$controller $controller} service is called | ||
with a string that does not match the supported controller string formats. | ||
|
||
Supported formats: | ||
|
||
1. `__name__` | ||
2. `__name__ as __identifier__` | ||
|
||
N'either `__name__` or `__identifier__` may contain spaces. | ||
|
||
Example of incorrect usage that leads to this error: | ||
```html | ||
<!-- unclosed ng-controller attribute messes up the format --> | ||
<div ng-controller="myController> | ||
``` | ||
|
||
or | ||
|
||
```js | ||
// does not match `__name__` or `__name__ as __identifier__` | ||
var myCtrl = $controller("mY contRoller", { $scope: newScope }); | ||
``` | ||
|
||
or | ||
|
||
```js | ||
directive("myDirective", function() { | ||
return { | ||
// does not match `__name__` or `__name__ as __identifier__` | ||
controller: "mY contRoller", | ||
link: function() {} | ||
}; | ||
}); | ||
``` | ||
|
||
To fix the examples above, ensure that the controller string matches the supported | ||
formats, and that any html attributes which are used as controller expressions are | ||
closed. | ||
|
||
|
||
Please consult the {@link ng.$controller $controller} service api docs to learn more. |
This file contains 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 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