简体   繁体   中英

Error: $injector:unpr Unknown Provider in angularjs with gulp-uglify

I've added .run function as follow:

coursesApp.run(['$rootScope'], function ($rootScope) {
    $rootScope.slugLinkCompany = function(item, link) {
        if (item) {
            var makeSlug = item.name.toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-');
            return item.name ? [link, makeSlug, item.id].join('/') : null;
        }
    };
    $rootScope.slugLinkCourse = function(item, link) {
        if (item) {
            var makeSlug = item.title.toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-');
            return item.title ? [link, makeSlug, item.id].join('/') : null;
        }
    };
    $rootScope.slugLinkCategory = function(item, link) {
        if (item) {
            var makeSlug = item.name.toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-');
            return item.name ? [link, makeSlug, item.id].join('/') : null;
        }
    };
});

Unfortunately when I uglify it, I've encountered following error.

Error: $injector:unpr
Unknown Provider

https://docs.angularjs.org/error/$injector/modulerr?p0=pwaCoursesApp&p1=Error:%20%5B$injector:unpr%5D%20http:%2F%2Ferrors.angularjs.org%2F1.3.8%2F$injector%2Funpr%3Fp0%3D%2524rootScope%0A%20%20%20%20at%20http:%2F%2Flocalhost:3000%2Fscripts%2Fmain.min.js:8:6739%0A%20%20%20%20at%20http:%2F%2Flocalhost:3000%2Fscripts%2Fmain.min.js:8:22851%0A%20%20%20%20at%20r%20(http:%2F%2Flocalhost:3000%2Fscripts%2Fmain.min.js:8:21847)%0A%20%20%20%20at%20Object.i%20%5Bas%20invoke%5D%20(http:%2F%2Flocalhost:3000%2Fscripts%2Fmain.min.js:8:22103)%0A%20%20%20%20at%20r%20(http:%2F%2Flocalhost:3000%2Fscripts%2Fmain.min.js:8:21317)%0A%20%20%20%20at%20http:%2F%2Flocalhost:3000%2Fscripts%2Fmain.min.js:8:21441%0A%20%20%20%20at%20o%20(http:%2F%2Flocalhost:3000%2Fscripts%2Fmain.min.js:8:7127)%0A%20%20%20%20at%20c%20(http:%2F%2Flocalhost:3000%2Fscripts%2Fmain.min.js:8:21218)%0A%20%20%20%20at%20Dt%20(http:%2F%2Flocalhost:3000%2Fscripts%2Fmain.min.js:8:22985)%0A%20%20%20%20at%20a%20(http:%2F%2Flocalhost:3000%2Fscripts% 2Fmain.min.js:8:12221

Please let me know anything I've missed. Thanks.

The dependency injection is done incorrectly:

//coursesApp.run(['$rootScope'], function ($rootScope) {
coursesApp.run(['$rootScope', function ($rootScope) {

  //Code here

//});
}]);

The dependency array needs to enclose both the injectables and the function itself.

For more information, see AngularJS Developer Guide - DI (Inline Array Annotation)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM