I encountered a problem with my minified AngularJS 1.x application
Uncaught Error: [$injector:unpr] Unknown provider: nProvider <- n
After following suggestions from similar questions, I implemented strict dependency injection during the bootstrap process of our application like this
angular.bootstrap(document, [app.name], {
strictDi: true
});
Even though I added this, I did not face any issues when running the application with non-minified code. However, when I minified the code, I started getting the unknown provider error. According to the AngularJS documentation, it should throw an error if there is any implicit annotation while using strict dependency injection. But for some reason, it was not happening.
I eventually discovered that the problem was in one of the directives which had a controller with an implicit annotation for $scope, as shown below
angular.module('MyModule', [])
.directive('myTabs', function() {
return {
restrict: 'E',
transclude: true,
scope: {},
controller: function MyTabsController($scope) {
var panes = $scope.panes = [];
$scope.select = function(pane) {
angular.forEach(panes, function(pane) {
pane.selected = false;
});
pane.selected = true;
};
this.addPane = function(pane) {
if (panes.length === 0) {
$scope.select(pane);
}
panes.push(pane);
};
},
templateUrl: 'my-tabs.html'
};
})
The issue was resolved after implementing Inline Array Annotation.
I am curious why strict DI did not throw any errors. Do I need to make any other changes to my code?"