Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS conflicts with JavaScript minifier

This is my code, which works fine:

angular.module('foo', []).config(
  function($locationProvider) {
    $locationProvider.html5Mode(true);
  }
);

However, after minification it looks like this:

angular.module('foo', []).config(function(n) { n.html5Mode(true); });

And AngularJS crashes with some internal exception. I think I understand why it crashes, but what is a workaround?

like image 338
Barbara Krein Avatar asked Jul 27 '26 13:07

Barbara Krein


1 Answers

It is very known and popular issue, you can inject your dependancies in this way

.directive('someDirective', ['$window', function ($window) { .....

You can learn more about it under this link

Another solution is to use ng-anotate

If you use Angular 1.3 you can turn on strictdi

replace this part

.config(
  function($locationProvider) {
    $locationProvider.html5Mode(true);
  }
);

to this

.config(['$locationProvider', function($locationProvider) {
    $locationProvider.html5Mode(true);
  }
]);
like image 116
Narek Mamikonyan Avatar answered Jul 30 '26 01:07

Narek Mamikonyan



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!