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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(injector): "strict-DI" mode which disables "automatic" function …
…annotation This modifies the injector to prevent automatic annotation from occurring for a given injector. This behaviour can be enabled when bootstrapping the application by using the attribute "ng-strict-di" on the root element (the element containing "ng-app"), or alternatively by passing an object with the property "strictDi" set to "true" in angular.bootstrap, when bootstrapping manually. JS example: angular.module("name", ["dependencies", "otherdeps"]) .provider("$willBreak", function() { this.$get = function($rootScope) { }; }) .run(["$willBreak", function($willBreak) { // This block will never run because the noMagic flag was set to true, // and the $willBreak '$get' function does not have an explicit // annotation. }]); angular.bootstrap(document, ["name"], { strictDi: true }); HTML: <html ng-app="name" ng-strict-di> <!-- ... --> </html> This will only affect functions with an arity greater than 0, and without an $inject property. Closes #6719 Closes #6717 Closes #4504 Closes #6069 Closes #3611
- Loading branch information
Showing
8 changed files
with
337 additions
and
33 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,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.
f5a04f5
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.
@caitp This commit shouldn't have been merged into 1.2.x branch. can you please revert it?
f5a04f5
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 thought it was a small enough feature that parity wouldn't hurt, but okay
f5a04f5
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.
This feature was probably removed from the 1.2.x branch and is not part of 1.2.17, yet it is still listed on the CHANGELOG.md as a new feature.
f5a04f5
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.
@IlanFrumer just removed it from the changelog... I think the changelog generator script is broken if its ignoring reverted commits