Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs $injector:unpr in the run method after minification

I'm using angular-xeditable on my Angular app. It works fine in develop environment but in production, when all js files are minify, I got this error:

Uncaught Error: [$injector:strictdi] http://errors.angularjs.org/1.3.5/$injector/strictdi?p0=function(n)

Searching on my code, I found that something goes wrong with xeditable. Here the app creation code 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 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 the code inside the run method, it doesn't throw the exception. This method is used to configure the xeditable as describe in the documentation. I can't figure out this strange behavior, Is there any way to see if the xeditable was successful added to the angular app or is there somenthing else to check?

like image 594
Darion Badlydone Avatar asked Jan 18 '26 15:01

Darion Badlydone


1 Answers

You have to inject the dependencies:

.run ( ['editableOptions', 'editableThemes', function(editableOptions, editableThemes)

Similarly to controllers, services, etc (remember to add a ] to before the ) of the run.

This is due to the fact that the minimizer such as uglify, change the variables names. In the way above, the minified code would be:

.run( ['editableOptions', 'editableThemes', function(n,t){

And n and t would be references to those dependencies.

like image 99
Michael Avatar answered Jan 20 '26 04:01

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!