This repository has been 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.5k
feat(injector): "strict-DI" mode which disables "automatic" function annotation / inferred dependencies #6719
Closed
+337
−33
Closed
Changes from all commits
Commits
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 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,54 @@ | ||
@ngdoc error | ||
@name $injector:strictdi | ||
@fullName Explicit annotation required | ||
@description | ||
|
||
This error occurs when attempting to invoke a function or provider which | ||
has not been explicitly annotated, while the application is running with | ||
strict-di mode enabled. | ||
|
||
For example: | ||
|
||
``` | ||
angular.module("myApp", []) | ||
// BadController cannot be invoked, because | ||
// the dependencies to be injected are not | ||
// explicitly listed. | ||
.controller("BadController", function($scope, $http, $filter) { | ||
// ... | ||
}); | ||
``` | ||
|
||
To fix the error, explicitly annotate the function using either the inline | ||
bracket notation, or with the $inject property: | ||
|
||
``` | ||
function GoodController1($scope, $http, $filter) { | ||
// ... | ||
} | ||
GoodController1.$inject = ["$scope", "$http", "$filter"]; | ||
|
||
angular.module("myApp", []) | ||
// GoodController1 can be invoked because it | ||
// had an $inject property, which is an array | ||
// containing the dependency names to be | ||
// injected. | ||
.controller("GoodController1", GoodController1) | ||
|
||
// GoodController2 can also be invoked, because | ||
// the dependencies to inject are listed, in | ||
// order, in the array, with the function to be | ||
// invoked trailing on the end. | ||
.controller("GoodController2", [ | ||
"$scope", | ||
"$http", | ||
"$filter", | ||
function($scope, $http, $filter) { | ||
// ... | ||
} | ||
]); | ||
|
||
``` | ||
|
||
For more information about strict-di mode, see {@link ng.directive:ngApp ngApp} | ||
and {@link api/angular.bootstrap angular.bootstrap}. |
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
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
Oops, something went wrong.
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.
Would it be better in the long run to pass the whole
config
object through tocreateInjector
?