Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error after Minification of angular js. Error: [$injector:unpr] Unknown provider: eProvider <- e <- makeErrorsDirective

I used Gulp to minify my entire js files. Once minified I got an error like the following:

[$injector:unpr] Unknown provider: eProvider <- e <- makeErrorsDirective.

I had a Custom directive in my controller file.

var myhubdashboardControllers = angular.module('vpdashboardmodule', []);

.directive('mhDashboard', function ($http, authService, apiService) {
    return {
        restrict: 'EA',
        scope: {
            name: '@',
            dash: '@',
            report: '@',
            disname: '@',
            disdesc: '@',
            distot: '@'
        },
        templateUrl: 'views/dashboard/dashboard-direc.html',
        link: function (scope, element, attr) {
            scope.linkChk = scope.name;
            switch (scope.linkChk) {
                case 'Shipped This Week':
                    scope.url = 'erp/JobShipmentList/PostCpsVwShipmentCount';
                    scope.shipstatus = "Departure";
                    scope.period = "ThisWeek";
                    scope.basicfilter = "Open";
                    scope.linkName = "Shipments";
                    scope.linkDesc = "Shipped This Week";
                    break;

}) };

This is the code used in my application.

like image 960
Dhamodharaan M Avatar asked Feb 01 '16 09:02

Dhamodharaan M


1 Answers

There is a reason why you have to inject services and controller in string array.

if you want to inject scope to controller, you have to use

angular.module('yourApp')
    .controller('yourController',['$scope',function($scope){
    }]);

Minification will change the variable names and if you don't use that array of strings while injecting services or controllers, it will be like

 angular.module('yourApp')
    .controller('yourController',function(e){
    });

So, angular will not be able to understand what 'e' stands for, hence the error. Always remember that the order is also important.

.directive('mhDashboard', ['$http','authService','apiService', function ($http, authService, apiService) {
    return {
        restrict: 'EA',
        scope: {
            name: '@',
            dash: '@',
            report: '@',
            disname: '@',
            disdesc: '@',
            distot: '@'
        },
        templateUrl: 'views/dashboard/dashboard-direc.html',
        link: function (scope, element, attr) {
            scope.linkChk = scope.name;
            switch (scope.linkChk) {
                case 'Shipped This Week':
                    scope.url = 'erp/JobShipmentList/PostCpsVwShipmentCount';
                    scope.shipstatus = "Departure";
                    scope.period = "ThisWeek";
                    scope.basicfilter = "Open";
                    scope.linkName = "Shipments";
                    scope.linkDesc = "Shipped This Week";
                    break;
}
}])
like image 51
Raghu Venmarathoor Avatar answered Oct 18 '22 15:10

Raghu Venmarathoor