angular-ui-router-title icon indicating copy to clipboard operation
angular-ui-router-title copied to clipboard

ngAnnotate just miss the $rootScope with default sample.

Open mutoo opened this issue 7 years ago • 2 comments

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!

mutoo avatar Mar 06 '17 10:03 mutoo

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

theanxy avatar Mar 15 '17 17:03 theanxy

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.

simonv3 avatar Apr 05 '17 00:04 simonv3