Javascript TypeError:api.getAll不是函数,无法识别服务方法

Javascript TypeError:api.getAll不是函数,无法识别服务方法,javascript,angularjs,dependency-injection,typeerror,angularjs-controller,Javascript,Angularjs,Dependency Injection,Typeerror,Angularjs Controller,我有一个非常简单的服务和一个控制器试图从中获取一些信息,但我一直在获取。methodName不是一个函数 这是服务,apiService.js: (function (module) { function api() { var sharedService = {}; sharedService = { getAll: function () { return 'test';

我有一个非常简单的服务和一个控制器试图从中获取一些信息,但我一直在获取。methodName不是一个函数

这是服务,apiService.js

(function (module) {

    function api() {

        var sharedService = {};

        sharedService = {

            getAll: function () {
                return 'test';
            }
        };
        return sharedService;

    }

    module.factory("api", api);


}(angular.module("anbud")));
然后我尝试在控制器中使用我的方法getAll,如下所示:

(function () {
    'use strict';

    angular.module('anbud')
      .controller('BasicExampleCtrl', ['$scope', 'api', function (api, $scope) {

           // on successfull request
          function onJson(json) {
              $scope.data = json;
          }

          // error getting json
          function onError() {
              throw 'error getting json';
          }

          function initialize() {

              api.getAll()
                  .then(onJson, onError);
          }

          initialize();

      }]);

}());
但我得到了一个错误:

TypeError: api.getAll is not a function
    at initialize (basic-example.js:67)

谢谢你的帮助

您已在
控制器
工厂函数内交换了依赖项序列,该序列必须与注入函数时包含在
DI数组
中的序列相同

代码

.controller('BasicExampleCtrl', ['$scope', 'api', function ($scope, api) { //<- first $scope then api.
.controller('BasicExampleCtrl',['$scope','api',function($scope,api){/像这样试试:

.controller('BasicExampleCtrl', ['$scope', 'api', function ($scope,api) {