Angularjs TypeError: <serviceName>.<functionName> is not a function at Scope.$scope.<functionName>

Angularjs TypeError: <serviceName>.<functionName> is not a function at Scope.$scope.<functionName>

我定义了一个服务:

'use strict';

angular.module('vAppName.services')
   .factory('UpdateWarehouse', function($resource, configSettings) {
     var updateWarehouse = $resource(configSettings.apiServiceUrl + 'api/v1/updateWarehouse', {
       'update': {
         method: 'POST'
       }
     });
     return updateWarehouse;
   }); 

在控制器中,列出控制器中的服务:

angular.module('vAppName.controllers')
    .controller('VCtrlName', [<list of other properties>'UpdateWarehouse',
        function(<list of other properties>, updateWarehouse) { 
        ...bunch of functions and properties

            $scope.updateWrh = function() {
                updateWarehouse.update({

                    startDate: $scope.updateWrhParams.startDate,
                    endDate: $scope.updateWrhParams.endDate

                }).$promise.then(function(){
                     $scope.messageModalVariables = {
            messageTitle: 'Warehouse Update Complete',
            messageDisplay: 'Warehouse has been updated.',
            messageType: 'Success',
            okIsHidden: false,
            yesNoIsHidden: true
          };
                    $scope.openMessageModal($scope.messageModalVariables);

                }, function (error) {
                     $scope.messageModalVariables = {
            messageTitle: 'Error Warehouse Update',
            messageDisplay: error.data,
            messageType: 'Error',
            okIsHidden: false,
            yesNoIsHidden: true
          };
          $scope.openMessageModal($scope.messageModalVariables);
                });
            };

        } //end main function
    ]);

这是HTML

<div style="margin: 5%; display: inline-block;">
                                <label id="startDateLabel" style="margin-left: 5%">Start Date:</label>
                                <date-picker id="startDatePicker" type="text" model="updateWrhParams.startDate" style="width: 50%; float: right;"></date-picker>
                            </div>
                            <div style="margin: 5%; display: inline-block;">
                                <label id="endDateLabel" style="margin-left: 5%">End Date:</label>
                                <date-picker id="endDatePicker" type="text" model="updateWrhParams.endDate" style="width: 50%; float: right;"></date-picker>
                            </div>
<button type="button" id="updateBtnWrh" class="btn btn-success" style="margin-left: 3%; background-color: #41a334;" ng-disabled="isAdmin == true" ng-click="updateWrh()">Update</button>

当我单击服务中的 Update' button, the functionupdateWrh()is called but theupdate' 函数时,系统未将其识别为函数。

为什么我的服务没有被识别为函数?

您没有正确定义 $resource。第二个参数是 paramDefaults 而不是 actions

 var updateWarehouse = $resource(URL, {}, {
   'update': {
     method: 'POST'
   }
 });

而不是

 var updateWarehouse = $resource(URL, {
   'update': {
     method: 'POST'
   }
 });