错误:工厂不是功能

时间:2016-07-08 16:06:07

标签: javascript angularjs factory typeerror

我在从工厂调用函数时遇到了一些问题。

我有一个看起来像这样的因素:

factory('UploadContracts',function($http, $q){
        return {
            uploadContractFile : function(url, requestData) {

              //Creating a deferred object
              var deferred = $q.defer();

              $http.post(
                "/cgoTruckWeb/resources/tarifErrors/uploadContracts",
                requestData,
                { headers: { 'Content-Type': undefined},
                  transformRequest: angular.identity
                }
              ).success(
                    function(responseData) {
                        //Passing data to deferred's resolve function on successful completion
                        deferred.resolve(responseData);
                    }
              ).error(
                    function(error) {          
                        deferred.reject(error);
                    }
              );           
              return deferred.promise;
            }
        };
    }).

我的控制器:

.controller(
                            "TarifErrorController",
                    [
                    "$scope",
                    "$route",
                    "$routeParams",
                    "$location",
                    "$modal",
                    "$http",
                    "TarifError",
                    "UploadContracts",
                    "DeleteErrorTarifs",
                    "Alert",
                    function($scope, $route, $routeParams, $location, $modal, $http, TarifError, DeleteErrorTarifs, UploadContracts, Alert) {

                      $scope.uploadContract = function() {
                            $scope.displayWaitingCursor = true;
                            // clear alerts
                            Alert.clear();
                            var fd = new FormData();
                            // Recup des informations stockées grace à "$scope.setFiles"
                            fd.append("contractFile",$scope.files[0]);

                            UploadContracts.uploadContractFile($scope.url, fd).then(
                                    function(data) {
                                        $scope.displayWaitingCursor = false;
                                        Alert.addInfo("info", "Contract uploaded successfully.");
                                    },
                                    function(error){
                                        Alert.addAlert("error", error);
                                        $scope.displayWaitingCursor = false;
                                    }
                                );      
                      }

由于某种原因,构建函数引发错误,说“错误:UploadContracts.uploadContractFile不是函数”

有人可以向我解释为什么构建函数不起作用吗?

0 个答案:

没有答案