我添加了 .run
函数,如下所示:
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;
}
};
});
不幸的是,当我丑化它时,我遇到了以下错误。
Error: $injector:unpr
Unknown Provider
请让我知道我错过的任何事情。谢谢。
最佳答案
依赖注入(inject)未正确完成:
//coursesApp.run(['$rootScope'], function ($rootScope) {
coursesApp.run(['$rootScope', function ($rootScope) {
//Code here
//});
}]);
依赖项数组需要包含可注入(inject)项和函数本身。
有关详细信息,请参阅 AngularJS Developer Guide - DI (Inline Array Annotation)
关于javascript - 错误: $injector:unpr Unknown Provider in angularjs with gulp-uglify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44193907/