javascriptangularjsangularjs-materialmddialog

Console Error in $element, while using $mdDialog of AngularJS Material


I'm trying to solve this error that shows in the console, it only occurs on the server, in my localhost the modal works correctly. Here's the error (click to open its link):

I have a view with the controller:

.when('/aseguradora', {
    templateUrl: 'views/insuranceagentdashboard.html',
    controller: 'InsuranceagentdashboardCtrl'
})

This is the controller:

angular.module('virtualApp').controller('InsuranceagentdashboardCtrl', ['$http', '$scope', 'pager', 'Dialogs', function($http, $scope, pager, Dialogs) {..

Inside the controller I have a function that executes the modal, (Dialogs is a service):

$scope.showCosignerFormDialog = function(insuranceRequest) {
    Dialogs.cosignerFormdialog(insuranceRequest);
}

In HTML I have an md-button with an ng-click

<md-button class="md-color-green" ng-click="showCosignerFormDialog(insuranceRequest)">VER SOLICITUD</md-button>

This is the Dialog service that executes the modal:

dialogs.cosignerFormdialog = function(insuranceRequest) {
    return $mdDialog.show({
        templateUrl: 'views/cosignerformdialog.html',
        autoWrap: false,
        controller: 'IdentityVerificationWizardCtrl',
        locals: {
            listing: insuranceRequest
        },
        preserveScope: true,            
        escapeToClose: false,
        fullscreen: true,
        clickOutsideToClose: true
    });
};

I do not know why this error can occur in the console being in the URL of the server, if I am in my localhost I do not get this error ...

THIS IS CONTROLLER identityverificationwizard.js:

angular.module('virtualApp').controller('IdentityVerificationWizardCtrl', ['$scope', 'upload', '$http', 'listing', '$routeParams', '$location', 'Dialogs', '$element', function($scope, upload, $http, listing, $routeParams, $location, Dialogs, $element) {
    $scope.propertyListing = listing;
    $scope.insuranceStudyContactInfo = {};
    $scope.insuranceStudyJobInfo = {};
    $scope.insuranceStudyFinancialInfo = {};
    $scope.insuranceStudyAssets = {};
    $scope.identityInfo = {
        date : moment('01/01/2000', 'DD/MM/YYYY').toDate()
    };
    $scope.virtualSignatureInfo = {};
    $scope.isCorporation = 'false';
    $scope.insuranceStudyJobInfo.publicOfficer = false;
    $scope.insuranceStudyJobInfo.managesPublicFunds = false;
    $scope.insuranceStudyJobInfo.linkedToRenownedPeople = false;
    $scope.insuranceStudyJobInfo.vatResponsible = false;
    $scope.insuranceStudyJobInfo.greatContributor = false;

    $scope.insuranceStudyFinancialInfo.doImport = false;
    $scope.insuranceStudyFinancialInfo.doExport = false;
    $scope.insuranceStudyFinancialInfo.doInvest = false;
    $scope.insuranceStudyFinancialInfo.doCurrencyExchange = false;
    $scope.insuranceStudyFinancialInfo.doPayServices = false;
    $scope.insuranceStudyFinancialInfo.doPayLoans = false;
    $scope.insuranceStudyFinancialInfo.doTransactions = false;

    $scope.rentProcessId = $scope.propertyListing.rentProcessId;
    $scope.cosignerKey = $location.search().cosignerKey;

    if ($scope.rentProcessId || $scope.cosignerKey) {
        $scope.readOnly = false;
    } else {
        $scope.readOnly = true;
    }

    $scope.setTabIndex = function(index) {
        $scope.tabIndex = index;
    }

    $scope.fileChanged = function(kind, file) {

        var reader = new FileReader();
        reader.onload = function(e) {
            if (kind == 'front') {
                $scope.frontIdFile = file;
                $scope.frontIdImage = e.target.result;
                $scope.$apply();
            } else {
                $scope.backIdFile = file;
                $scope.backIdImage = e.target.result;
                $scope.$apply();
            }
        };
        reader.readAsDataURL(file.files[0]);
        $scope.$apply();
    }

    $scope.uploadForm = function() {
        var params = {};

        if ($scope.insuranceStudyContactInfo.city) {
            $scope.insuranceStudyContactInfo.cityCode = $scope.insuranceStudyContactInfo.city.cityCode;
        }

        if ($scope.insuranceStudyJobInfo.city) {
            $scope.insuranceStudyJobInfo.cityCode = $scope.insuranceStudyJobInfo.city.cityCode;
        }
        if ($scope.insuranceStudyAssets.hasProperties) {
            if ($scope.insuranceStudyAssets.property1 && $scope.insuranceStudyAssets.property1.city) {
                $scope.insuranceStudyAssets.property1.cityCode = $scope.insuranceStudyAssets.property1.city.cityCode || null;
            } else {
                delete $scope.insuranceStudyAssets.property1;
            }

            if ($scope.insuranceStudyAssets.property2 && $scope.insuranceStudyAssets.property2.city) {
                $scope.insuranceStudyAssets.property2.cityCode = $scope.insuranceStudyAssets.property2.city.cityCode || null;
            } else {
                delete $scope.insuranceStudyAssets.property2;
            }
        } else {
            delete $scope.insuranceStudyAssets.property1;
            delete $scope.insuranceStudyAssets.property2;
        }

        if ($scope.propertyListing.rentProcessId) {
            params.rentProcessId = $scope.propertyListing.rentProcessId;
        }

        if ($location.search().cosignerKey) {
            params.cosignerKey = $location.search().cosignerKey;
        }

        if ($scope.identityInfo.date) {
            $scope.identityInfo.birthDate = formatedDate($scope.identityInfo.date, 'DD/MM/YYYY');
        }
        $scope.insuranceStudyFinancialInfo.doImport = $scope.insuranceStudyFinancialInfo.doImport || false;
        $scope.insuranceStudyFinancialInfo.doExport = $scope.insuranceStudyFinancialInfo.doExport || false;
        $scope.insuranceStudyFinancialInfo.doInvest = $scope.insuranceStudyFinancialInfo.doInvest || false;
        $scope.insuranceStudyFinancialInfo.doCurrencyExchange = $scope.insuranceStudyFinancialInfo.doCurrencyExchange || false;
        $scope.insuranceStudyFinancialInfo.doPayServices = $scope.insuranceStudyFinancialInfo.doPayServices || false;
        $scope.insuranceStudyFinancialInfo.doPayLoans = $scope.insuranceStudyFinancialInfo.doPayLoans || false;
        $scope.insuranceStudyFinancialInfo.doTransactions = $scope.insuranceStudyFinancialInfo.doTransactions || false;

        params.isCorporation = $scope.isCorporation;
        params.contactInfo = JSON.stringify($scope.insuranceStudyContactInfo);
        params.jobInfo = JSON.stringify($scope.insuranceStudyJobInfo);
        params.financialInfo = JSON.stringify($scope.insuranceStudyFinancialInfo);
        params.assets = JSON.stringify($scope.insuranceStudyAssets);
        params.virtualSignatureInfo = JSON.stringify($scope.virtualSignatureInfo);
        params.identityInfo = JSON.stringify($scope.identityInfo);

    $scope.isReadOnly = function() {
        if ($scope.readOnly) {
            $http.get(root + "Insurance/s/getInsuranceRequest", {
                params: {
                    insuranceRequestId: $scope.propertyListing.insuranceRequestId
                }
            }).then(function(res) {
                $scope.code = res.data.code;
                $scope.type = res.data.type;
                $scope.datetime = res.data.datetime;
                $scope.status = res.data.status;
                $scope.listingCode = res.data.listingCode;
                $scope.isCorporation = res.data.corporation + "";
                $scope.identityInfo.documentTypeCode = res.data.identityInfo.documentTypeCode;
                $scope.identityInfo.documentNumber = res.data.identityInfo.documentNumber;
                $scope.identityInfo.names = res.data.identityInfo.names;
                $scope.identityInfo.lastNames = res.data.identityInfo.lastNames;
                $scope.identityInfo.date = res.data.identityInfo.birthDate;
                $scope.insuranceStudyContactInfo = res.data.contactInfo;
                $scope.insuranceStudyJobInfo = res.data.jobInfo;
                $scope.insuranceStudyFinancialInfo = res.data.financialInfo;

                if ($scope.insuranceStudyFinancialInfo.foreignAccountBank) {
                    $scope.insuranceStudyFinancialInfo.doForeignAccount = true;
                }
                if ($scope.insuranceStudyFinancialInfo.foreignAccount) {
                    $scope.insuranceStudyFinancialInfo.doForeignAccount = true;
                }
                if ($scope.insuranceStudyFinancialInfo.foreignAccountCurrency) {
                    $scope.insuranceStudyFinancialInfo.doForeignAccount = true;
                }
                if ($scope.insuranceStudyFinancialInfo.foreignAccountCountry) {
                    $scope.insuranceStudyFinancialInfo.doForeignAccount = true;
                }
                if ($scope.insuranceStudyFinancialInfo.foreignAccountCity) {
                    $scope.insuranceStudyFinancialInfo.doForeignAccount = true;
                }
                if ($scope.insuranceStudyFinancialInfo.doImport) {
                    $scope.insuranceStudyFinancialInfo.doInternationalOperations = true;
                }
                if ($scope.insuranceStudyFinancialInfo.doExport) {
                    $scope.insuranceStudyFinancialInfo.doInternationalOperations = true;
                }
                if ($scope.insuranceStudyFinancialInfo.doInvest) {
                    $scope.insuranceStudyFinancialInfo.doInternationalOperations = true;
                }
                if ($scope.insuranceStudyFinancialInfo.doCurrencyExchange) {
                    $scope.insuranceStudyFinancialInfo.doInternationalOperations = true;
                }
                if ($scope.insuranceStudyFinancialInfo.doPayServices) {
                    $scope.insuranceStudyFinancialInfo.doInternationalOperations = true;
                }
                if ($scope.insuranceStudyFinancialInfo.doPayLoans) {
                    $scope.insuranceStudyFinancialInfo.doInternationalOperations = true;
                }
                if ($scope.insuranceStudyFinancialInfo.doTransactions) {
                    $scope.insuranceStudyFinancialInfo.doInternationalOperations = true;
                }


                $scope.insuranceStudyAssets = res.data.assets;

                if ($scope.insuranceStudyAssets.property1 || $scope.insuranceStudyAssets.property2) {
                    $scope.insuranceStudyAssets.hasProperties = true;
                }

                if ($scope.insuranceStudyAssets.vehicle1 || $scope.insuranceStudyAssets.vehicle2) {
                    $scope.insuranceStudyAssets.hasCars = true;
                }

                $scope.availableActions = res.data.availableActions;
            });
        }
    }
    $scope.isReadOnly();
}]);

Solution

  • That error says your are using an unknown dependency in your controller. Here, the error says that the "unknown dependency" is a provider called $element.

    ! There are 3 types of providers in angularjs: service, factory or provider

    2 reasons why you can have this problem:

    1) If you don't have any providers (service, factory or provider) called $element in your project you shouldn't have a dependency for it. In IdentityVerificationWizardCtrl

    Instead of:

    .controller('IdentityVerificationWizardCtrl', ['$scope', 'upload', '$http', 'listing', '$routeParams', '$location', 'Dialogs', '$element', function($scope, upload, $http, listing, $routeParams, $location, Dialogs, $element)
    

    Write:

    .controller('IdentityVerificationWizardCtrl', ['$scope', 'upload', '$http', 'listing', '$routeParams', '$location', 'Dialogs', function($scope, upload, $http, listing, $routeParams, $location, Dialog)
    

    2) if you have a provider called $element , maybe you didn't call it into your index.html

    PS: In angularjs, $element is a parametter used into the link function and refer to the DOM element. So IMO opinion your error is because of reason 1