Angularjs $ injector: unpr in startup method after minification
I am using angular -xeditable in my Angular app. It works fine in development environment, but in production when all js files are minified I got this error:
Uncaught Error: [$injector:strictdi] http://errors.angularjs.org/1.3.5/$injector/strictdi?p0=function(n)
Searching through my code, I found something went wrong with xeditable. Here's the code for creating the app in coffescript:
# create the angular app
angular.module 'dbManagerApp', ['xeditable', 'ngDraggable']
# set the theme for the xeditable
.run (editableOptions, editableThemes) ->
# set the default theme
editableOptions.theme = 'default'
# override the ok button
editableThemes['default'].submitTpl = '<div class="small primary btn"><input type="submit" value="Ok" /></div>'
# override the cancel button
editableThemes['default'].cancelTpl = '<div class="small warning btn" ng-click="$form.$cancel()"><a href="#">Cancel</a></div>'
And here's the minify version:
(function(){angular.module("dbManagerApp",["xeditable","ngDraggable"]).run(function(n,t){if(!_.isUndefined(n||_.isUndefined(n.theme)))return n.theme="default",t["default"].submitTpl='<div class="small primary btn"><input type="submit" value="Ok" /><\/div>',t["default"].cancelTpl='<div class="small warning btn" ng-click="$form.$cancel()"><a href="#">Cancel<\/a><\/div>'})}).call(this);
//# sourceMappingURL=DbManagerApp.min.js.map
If I comment out the code inside the run method, it doesn't throw an exception. This method is used to configure xeditable as described in the documentation . I cannot figure out this strange behavior. Is there a way to find out if xeditable has been successfully added to the Angular app or is there anything else to check?
source to share
You have to inject dependencies:
.run ( ['editableOptions', 'editableThemes', function(editableOptions, editableThemes)
Similar to controllers, services, etc. (don't forget to add ]
before )
to run.
This is because a minimizer like uglify changes variable names. In the method above, the minicode will look like this:
.run( ['editableOptions', 'editableThemes', function(n,t){
And n
and t
will be links to these dependencies.
source to share