Helpex - Trao đổi & giúp đỡ Đăng nhập
4

Mặc dù tôi đã quen với vấn đề uglify khi sử dụng Angular , nhưng tôi lại bắt đầu gặp phải vấn đề này ngay bây giờ với một chỉ thị cụ thể, ngay cả khi tôi đang sử dụng kiểu giống mảng để khai báo phụ thuộc:

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

Tệp chính của tôi khai báo các mô-đun một cách riêng biệt.

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'])

Bây giờ, khi tôi sử dụng chỉ thị này, tôi nhận được eProvider chưa biết <- e vấn đề

Lỗi: [$ injectionor: unr ] http://errors.angularjs.org/1.4.8/ $ injectionor / unr? P0 = rProvider% 20% 3C-% 20r

Tôi đang sử dụng như thế này:

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

Nếu tôi xóa thẻ miền-img , sự cố sẽ biến mất. Ngoài ra, nếu tôi không xác minh mã, vấn đề cũng sẽ biến mất.

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/'));
})

Tôi đã hy vọng tôi có thể hiểu được một số điểm mà tôi có thể đã sai trong chỉ thị cụ thể này.

Cảm ơn bạn trước.

4 hữu ích 0 bình luận 1.4k xem chia sẻ
3

Bạn đã bỏ lỡ làm theo chú thích mảng nội tuyến của DI như đối với bộ điều khiển chỉ thị của bạn.

Mã số

controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
      $attrs.$set('ngSrc', Endpoint + $attrs.ngSrc);
}]`
3 hữu ích 1 bình luận chia sẻ
1

Bạn cần thay đổi cú pháp của controllerchỉ thị của mình như sau:

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

Nhìn vào điều này để biết thêm một số chi tiết.

1 hữu ích 0 bình luận chia sẻ
1

Hoặc bạn có thể để nguyên như hiện tại và sử dụng GulpJS để làm chú thích cho bạn. Trong dự án SkeletonSPA của tôi, tôi cũng làm như vậy.

Tôi sử dụng plugin GulpJS gulp-ng-annotate để thực hiện việc này cho tôi. Nhiệm vụ Gulp của bạn trông sẽ giống như sau:

// require gulp-ng-annotate plugin
let ngannotate = require('gulp-ng-annotate');

// 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(ngannotate({gulpWarnings: false})) // annotate angular DI
  .pipe(concat('app.min.js'))
  .pipe(uglify()) // do the minification
  .pipe(gulp.dest('dist/'));

Bằng cách này, bạn sẽ không phải tự làm và nhiệm vụ Gulp của bạn sẽ làm điều đó cho bạn ;-)

1 hữu ích 1 bình luận chia sẻ
loading
Không tìm thấy câu trả lời bạn tìm kiếm? Duyệt qua các câu hỏi được gắn thẻ javascript angularjs dependency-injection gulp bundling-and-minification , hoặc hỏi câu hỏi của bạn.

Có thể bạn quan tâm

loading