我有应用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文件(index.js)中调用此类
var init = new EC.Bootstrap();
我非常困惑,因为它必须工作,但它不适用于Android设备(手机)和Android模拟器
我试图使用很多变种,但它们也不起作用,无论如何这种情况必须起作用
我在调试此代码时遇到问题我无法获得错误但是简单的角度片不适用于版本1并适用于版本2
UPD: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
答案 0 :(得分:0)
试试这个
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文件中的“服务”和“控制器”