When I converted my AngularJS Service to TypeScript and used the "export" keyword, it became available for import in a TypeScript controller...
But how can I still inject it into old controllers?
To explain in detail, I am transitioning my controllers to services in TypeScript in preparation for migrating from angularjs to angular 2.x in the future. Here is an example of a service called "equipmentAreaStorageT" using TypeScript...
<reference path="../../Scripts/typings/angularjs/angular.d.ts" />
import { UrlService } from '../../Scripts/app/services/urlService';
export class EquipmentAreaStorageT {
keyPrefix = "";
api = "";
index = "";
constructor(private isl3UrlService: UrlService) {
var _this = this;
this.keyPrefix = "EquipmentAreaStorageT";
this.api = "api/equipmentAreaApi/";
this.index = "EquipmentArea";
}
getIndexUrl() {
return this.isl3UrlService.getPath + this.index;
}
}
angular.module('main').service('equipmentAreaStorageT', EquipmentAreaStorageT);
I know that using the Import keyword should be sufficient for injecting this into a TypeScript Controller.
import { EquipmentAreaStorageT } from '../EquipmentArea/EquipmentAreaStorageT';
export class EquipmentAreaControllerT {
$inject = ["$scope"];
entity = {};
isOpen = false;
gridOptions = {};
isl3SelectionService = {};
isl3DialogService = {};
constructor($scope, private isl3EquipmentAreaStorage: EquipmentAreaStorageT) {
var _this = this;
var ctrl = $controller("baseEditOnGridController", { $scope: this, storage: isl3EquipmentAreaStorage});
ctrl.loadRecords();
}
}
angular.module('main').controller('EquipmentAreaControllerT', EquipmentAreaControllerT);
However, I do not want to convert all my Controllers to TypeScript right now. So, how can I use this new TypeScript service in my old .js controller? I tried the following example...
appRoot.controller("EquipmentAreaController", [
"$scope", "equipmentAreaStorageT"
function ($scope, equipmentAreaStorageT) {
$scope.entity = {};
$scope.isOpen = false;
$controller("baseEditOnGridController", { $scope: $scope, storage: equipmentAreaStorageT});
$scope.loadRecords();
}
]);
But I always get this error: Object.defineProperty(exports, "__esModule", { value: true });
I am working with Visual Studio and have added the necessary types for working with TypeScript.