0

I have the following code, on compile I run through ngAnnotate and uglify

angular.bootstrap(navWrap, ['my.navbar']);

Now I know this is a little unconventional but it works when not minified. However, when I try to minify it causes a provider not found exception.

this is a similar question only its suggestion to use ngMin (ngAnnotate) I am already doing. If I turn off mangling then everything works but this seems like a bad idea.

If I simply change to the ng-app in the tag it works fine. Any ideas?

Community
  • 1
  • 1
Jackie
  • 21,969
  • 32
  • 147
  • 289

1 Answers1

1

It's impossible for ng-annotate to detect all pieces that need inject annotations. For example the resolve properties used in routing are not annotated automatically:

app.config(function ($routeProvider) {
  $routeProvider.when('/', {
    templateUrl: 'home.html',
    controller: 'HomeCtrl',

    resolve: {

      // This needs annotations when minimized

      myArgument: function(myService) {
        return myService.getMyArgument();
      }
    }

  }).otherwise({
    redirectTo: '/'
  });
});

So you can either annotate it yourself ... :

resolve: {
   // This needs annotations when minimized

  myArgument: ['myService', function(myService) {
    return myService.getMyArgument();
  }]
}

... or try to mark it with "ngInject", which should help ng-annotate to locate functions that need injection:

resolve: {
   // This needs annotations when minimized

  myArgument: function(myService) {
    "ngInject";
    return myService.getMyArgument();
  }
}
null
  • 7,906
  • 3
  • 36
  • 37
  • So how would this relate to angular.bootstrap? Does this mean I would need to apply this to all modules? Why does it seem to work fine as ng-app? – Jackie Mar 27 '15 at 14:42
  • Also how would this would if the module was in one JS file (minified using ngAnnotate) and the other was minified using an asset pipeline or other means? – Jackie Mar 27 '15 at 14:44
  • I am not quite sure why the `ng-app` works in your case and the bootstrap not. Do you have multiple custom modules? You could try bootstrapping them one by one to locate where the issue occurs. If you remove the bootstrapping and the `ng-app` all together, do you still get an exception? Keeping the files separate or crunching them in one minified file should not make any difference. – null Mar 27 '15 at 15:14
  • Tried to work on this and the real problem is they are so interconnected. I did manage to comment out all the connections and load them independently, however, each one seems to fail the exact same way. I am trying to put together more information now. We compile to one large JS so debugging has been a bit tough. – Jackie Mar 27 '15 at 15:18