nonplus / angular-ui-router-title

AngularJS module for updating browser title/history based on the current ui-router state.
122 stars 30 forks source link

ngAnnotate just miss the $rootScope with default sample. #11

Open mutoo opened 7 years ago

mutoo commented 7 years ago

I was using the ngAnnotate and uglifyjs in my project.

When I introduced the sample code into my file, it breaked the page after build.

$titleProvider.documentTitle(function($rootScope) {
    return $rootScope.$title ? $rootScope.$title + " - My Application" : "My Application";
});

It took a long time to find the reason before I awared that there is a dependency injection of $rootScope.

So I manually add the annotation for the sample code:

$titleProvider.documentTitle(["$rootScope", function($rootScope) {
    return $rootScope.$title ? $rootScope.$title + " - My Application" : "My Application";
}]);

or you can just use the "ngInject" directive:

$titleProvider.documentTitle(function($rootScope) {
    "ngInject";
    return $rootScope.$title ? $rootScope.$title + " - My Application" : "My Application";
});

it works again!

theanxy commented 7 years ago

I confirm, the fix above addressed errors in my project as well. Thanks @mutoo!

simonv3 commented 7 years ago

I think this might go a bit deeper than just making sure that $rootScope gets injected into the provider.

When I run grunt-ng-annotate this line causes it to error. When I comment out that line the error disappears. grunt-ng-annotate completes fine otherwise.