сервис бросает ошибку в контроллере как функция не определена - PullRequest
0 голосов
/ 22 марта 2019
amcApp.service('utilService', function ($http, $q,$rootScope) {
    var getSupportTypes = function () {

        var deferred = $q.defer();
        $http.get($rootScope.BaseUrl+'vendor/supportTypes')
            .then(function daoSuccess(response) {
                console.log("Getting Sub Customer Service call success ", response);
                deferred.resolve(response);
            }, function daoError(reason) {
                console.log("Getting SubC data service call error", reason);
                deferred.reject(reason);
            });
        return deferred.promise;
    };
    return{
        getSupportTypes : getSupportTypes,       
    };
});

Выше определен сервис, который я определил.

Ниже указан контроллер, который я определил.

amcApp.controller('contractForm', ['$scope', '$http','$rootScope','$filter', '$uibModal', '$state', 'testService','utilService','contractService',
 function ($scope, $http,$rootScope, $filter,$uibModal, testService,utilService,contractService) {
          //Service of getting the Support Types.
        utilService.getSupportTypes().then(function(response){
                        $scope.supportTypes = response.data.UtilDataType;
        });
}]);

Это ошибка, которую я получаю enter image description here

Могу ли я получить какие-либо предложения?

1 Ответ

0 голосов
/ 22 марта 2019

Проверьте зависимости, которые вы вводите в контроллер, у вас есть лишнее состояние $ в массиве, которое не было передано функции.Я бы предложил удалить как следующее:

amcApp.controller('contractForm', ['$scope', '$http', '$rootScope', '$filter', '$uibModal', 'testService','utilService','contractService',
 function ($scope, $http, $rootScope, $filter, $uibModal, testService, utilService, contractService) {
   //Service of getting the Support Types.
   utilService.getSupportTypes().then(function (response){
      $scope.supportTypes = response.data.UtilDataType;
   });
}]);

С другой стороны, я просто удалил бы все неиспользуемые сервисы, я полагаю, что это тоже работает нормально:

amcApp.controller('contractForm', ['$scope', 'utilService', function ($scope, utilService) {
   //Service of getting the Support Types.
   utilService.getSupportTypes().then(function (response) {
      $scope.supportTypes = response.data.UtilDataType;
   });
}]);

Просто предложение - если вы сохраняете свой код в чистоте, гораздо проще выяснить причину любых проблем.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...