无法向控制器 angularJs + CordovaJs (TypeScript) 注入服务

Can't inject service to controller angularJs + CordovaJs (TypeScript)

我有应用angularJs + CordovaJs + TypeScript 我尝试向控制器注入服务

module EC {
export class Bootstrap {
constructor($scope) {
  angular.module('ec', ['ec.services', 'ec.controllers']);
  angular.module('ec.services', []);
  angular.module('ec.controllers', []);

  //Constructor for class EC.Services.DataProxyService called
  angular.module('ec.services').factory("DataProxyService", EC.Services.DataProxyService);

  //Version 1
  // It is not working. Alert doesn't call
  angular.module('ec.controllers').controller("HomeController", ['$scope', 'DataProxyService', EC.Controllers.HomeController]);

  //Version 2
  //If I change previous on that
  //it work's but I don't have access to DataProxyService
  //angular.module('ec.controllers').controller("HomeController", ['$scope', EC.Controllers.HomeController]);
    }
  }
}

在单独的 javascript 文件中调用此 class (index.js)

   var init = new EC.Bootstrap();

我很困惑,因为它必须工作,但在 android 设备(移动 phone)和 android 模拟器

上不工作

我尝试了很多变体,但它们都不起作用,无论如何这个案例必须起作用

我在调试这段代码时遇到问题我无法得到错误但是简单的 angular 部分不适用于版本 1 而适用于版本 2

更新:2 我使用 gulp 所以我得到下一个文件作为结果:

    /// <reference path="references.ts" />
var EC;
(function (EC) {
    var Bootstrap = (function () {
        function Bootstrap($scope) {
            angular.module('ec', ['ec.services', 'ec.controllers']);
            angular.module('ec.services', []);
            angular.module('ec.controllers', []);
            //Constructor for class EC.Services.DataProxyService called
            angular.module('ec.services').factory("DataProxyService", EC.Services.DataProxyService);
            //Version 1
            // It is not working. Alert doesn't call
            angular.module('ec.controllers').controller("HomeController", ['$scope', 'DataProxyService', EC.Controllers.HomeController]);
            //Version 2
            //If I change previous on that
            //it work's but I don't have access to DataProxyService
            //angular.module('ec.controllers').controller("HomeController", ['$scope', EC.Controllers.HomeController]);
        }
        return Bootstrap;
    })();
    EC.Bootstrap = Bootstrap;
})(EC || (EC = {}));
//# sourceMappingURL=boot.js.map
//// <reference path="../scripts/typings/tsd.d.ts" />
//// <reference path="../../typings/kendo.all.d.ts" />
//// <reference path="../../typings/api.d.ts" />
//# sourceMappingURL=references.js.map
/// <reference path="../references.ts" />
var EC;
(function (EC) {
    var Controllers;
    (function (Controllers) {
        var HomeController = (function () {
            /*@ngInject*/
            function HomeController($scope, dataProxyService) {
                this.name = "Smith";
                alert('HomeController');
                alert($scope);
                alert(dataProxyService);
                $scope.vm = this;
            }
            return HomeController;
        })();
        Controllers.HomeController = HomeController;
    })(Controllers = EC.Controllers || (EC.Controllers = {}));
})(EC || (EC = {}));
//# sourceMappingURL=home-controller.js.map
/// <reference path="../references.ts" />
var EC;
(function (EC) {
    var Services;
    (function (Services) {
        var DataProxyService = (function () {
            /*@ngInject*/
            function DataProxyService() {
                alert('DataProxyService');
            }
            return DataProxyService;
        })();
        Services.DataProxyService = DataProxyService;
    })(Services = EC.Services || (EC.Services = {}));
})(EC || (EC = {}));
//# sourceMappingURL=dataProxyService.js.map

试试这个

module EC {
  export class Bootstrap {
constructor($scope) {
  angular.module('EC', []);
  angular.module('Services', []);

  //Constructor for class EC.Services.DataProxyService called
  angular.module('Services').service("DataProxyService", [Services.DataProxyService]);

  //Version 1
  // It is not working. Alert doesn't call
  angular.module('EC', ['Services']).controller("HomeController", ['$scope', 'DataProxyService', Controllers.HomeController]);

  //Version 2
  //If I change previous on that
  //it work's but I don't have access to DataProxyService
  //angular.module('ec.controllers').controller("HomeController", ['$scope', EC.Controllers.HomeController]);
}  }}

将模块名称更改为简单名称,如 *.ts 文件中的 "Service" 和 "Controller"