I am trying to debug a missing provider in a large-ish AngularJS project. The error is a missing 'dProvider'. It is only occurring on a version of the code that is minified, which makes sense, because we have no 'd' controllers, factories, or services. I am having trouble finding what is causing this, and searching through the minified code for things like function(a,b,c,d) hasn't yielded anything yet. Is there any way to force only explicit dependency injection in Angular? It seems like if I could force this I could catch the problem in the dev environment.
-
1try generating a source map file during your minification process - that way you should be able to determine the name of the missing provider here is a arcticle on sourcemapsMark-Sullivan– Mark-Sullivan2014-02-19 21:10:16 +00:00Commented Feb 19, 2014 at 21:10
-
This could happen if you forgot to min-safe an injection. If you don't have a 'd' service it sounds like your parameters got mangled.Nick– Nick2014-02-19 21:12:34 +00:00Commented Feb 19, 2014 at 21:12
-
I hadn't thought of source maps. That's a good idea, but according to this, source map generation with grunt is probably beyond what I'm able to do for the moment. I understand why i could get an error like this, I'm just having trouble finding it. I'm also not confident a source map would help, because the stack trace only lists functions within angular.js, not my minified code.xdhmoore– xdhmoore2014-02-19 21:30:02 +00:00Commented Feb 19, 2014 at 21:30
3 Answers
Yippee! Since Angular 1.3.1 you can turn off implicit dependency injection!
From code, using strictDi config property:
angular.bootstrap(document, ['myApp'], {
strictDi: true
});
Or from template, using ng-strict-di directive:
<html ng-app="myApp" ng-strict-di>
1 Comment
Wow that sucks.
It's probably a controller/service defined like this
app.controller('myCtrl', function($scope){
...
})
instead of the safer
app.controller('myCtrl', ['$scope', function($scope){
...
}])
I don't have a fool-proof answer but maybe you can search for ', function( and if you get lucky you'll find the culprit. If something like that doesn't work, source maps are probably the way to go.
3 Comments
I ended up selectively commenting out portions of my html until I determined where the issue was occurring. Turns out it was an angular-ui-bootstrap issue.