gpt4 book ai didi

javascript - Gulp uglify 导致 AngularJS 无法解决提供者问题

转载 作者:行者123 更新时间:2023-11-29 10:10:27 25 4
gpt4 key购买 nike

虽然我熟悉使用 Angular 时的 uglify 问题,但我现在使用特定指令再次遇到这个问题,即使我使用类似数组的样式进行依赖声明:

angular.module('app.directives').directive('domainImg', ['Endpoint', function (Endpoint) {
return {
restrict: 'A',
controller: function ($scope, $element, $attrs) {
$attrs.$set('ngSrc', Endpoint + $attrs.ngSrc);
}
};
}]);

我的主文件分别声明了模块。

angular.module('app.providers', []).constant('Endpoint', 'http://www.multzfidelidade.com.br/sistema/');
angular.module('app.tools', []);
angular.module('app.services', []);
angular.module('app.resources', []);
angular.module('app.controllers', []);
angular.module('app.directives', []);
angular.module('App', ['ui.mask', 'templates', 'app.providers', 'app.tools', 'app.services', 'app.resources', 'app.controllers', 'app.directives'])

现在,当我使用这个指令时,我遇到了unknown eProvider <- e 问题

Error: [$injector:unpr] http://errors.angularjs.org/1.4.8/$injector/unpr?p0=rProvider%20%3C-%20r

我是这样使用的:

<img class="prize-directive-image" ng-src="{{prize.image}}" domain-img/>

如果我删除 domain-img 标签,问题就会消失。另外,如果我不丑化代码,问题也会消失。

gulp.task('default', function () {
// Concat all JS files into a single one called app.min.js
gulp.src(['public_html/js/*.js', 'public_html/js/**/*.js', 'public_html/*.js', 'public_html/modules/**/*.js', '!public_html/app.min.js'])
.pipe(concat('app.min.js'))
// .pipe(uglify()) // Without this line the problem doesn't happen
.pipe(gulp.dest('dist/'));

// Concat all HTML directives into a single one
gulp.src('public_html/js/**/**/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(templateCache('templates.min.js', {standalone: true}))
.pipe(gulp.dest('dist/'));
})

我希望我能深入了解我在这个特定指令中可能出错的地方。

提前谢谢你。

最佳答案

您错过了像指令 Controller 一样遵循 DI 的内联数组注释。

代码

controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
$attrs.$set('ngSrc', Endpoint + $attrs.ngSrc);
}]`

关于javascript - Gulp uglify 导致 AngularJS 无法解决提供者问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34517557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com