Cannot inject service for angularJs + CordovaJs controller (TypeScript)
I have angularJs + CordovaJs + TypeScript app I am trying to inject a service into a controller
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 but I don't have access to DataProxyService
//angular.module('ec.controllers').controller("HomeController", ['$scope', EC.Controllers.HomeController]);
}
}
}
Calling this class into a separate javascript file (index.js)
var init = new EC.Bootstrap();
I am very confused because it should work but it doesn't work on Android device (mobile phone) and Android emulator.
I tried many options but they didn't work either and this case should work anyway
I have a problem debugging this code. I can't get the error, but the simple angular part doesn't work for version 1 and works for version 2
UPD: 2 I am using gulp, so I am getting the following file as output:
/// <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 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
+3
source to share
1 answer
try it
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 but I don't have access to DataProxyService
//angular.module('ec.controllers').controller("HomeController", ['$scope', EC.Controllers.HomeController]);
} }}
Change the module name to a simple name such as "Service" and "Controller" in * .ts files.
0
source to share