Search code examples
angularjstypescriptes6-module-loader

ES6 Module Loader Doesn't Load Angular Controller written using TypeScript


I am trying to convert Javascript angular modules in to TypeScript. Currently I am using ES6 Module Loader. And Trying to convert each module one by one. I did convert one module to TypeScript, but having issues with ES6 loader not loading controllers and directives.

Here is my app.js:

 import {editFieldModule} from './modules/field/editField/editField.module';
 //Some other Angular Modules written ES6 ///
 export var comp = angular.module('comp',[ "comp.modules.editField",//someother]);

Here is my Angular module written in TypeScript.

 var editFieldModule: ng.IModule = angular.module("comp.modules.editField", []);
 export {editFieldModule};

Here is my Controller.

 /// <reference path="../../../../thirdparty/angular-material/angular-material.d.ts"/>
 /// <reference path="../../../../thirdparty/angular/angular.d.ts"/>
 /// <reference path="../../../../thirdparty/angular-ui-router/api/angular-ui-router.d.ts"/>


module features.editField {
var app = angular.module('comp.modules.editField');
export class EditFieldController {

    static $inject: string[] = ["$mdDialog", "$state"];

    constructor(private _mdDialog: any, private _state: ng.ui.IStateService) {}

    showConfirmation(ev: any) {
        let tempThis = this;
        tempThis._mdDialog.show({
            controller: 'editFieldCancelDialogController',
            controllerAs: 'vm',
            templateUrl: 'test.html',
            parent: angular.element(document.body),
            targetEvent: ev
        });
    }
  }
 app.controller('editFieldController', features.editField.EditFieldController);
}

Here is my directive.

module features.editField {
var app = angular.module('comp.modules.editField');
export class EditFieldDirective implements ng.IDirective {        

    public restrict: string = 'E';
    public controller: string = 'editFieldController';
    public templateUrl: string = 'app/modules/field/editField/editField.tmpl.html';
    public controllerAs: string = 'vm';
    public bindToController: boolean = true;
    public link = function() {
            console.log('instantiating directive!');
        }        
    }
app.directive("efpEditField", [() => new features.editField.EditFieldDirective()]);
}

I can see that my module is being loaded but the controller and directive are never registered and not downloaded at all. Can any one tell me where I am doing the mistake.


Solution

  • Figured it. I need to import controller and directive in my module.

    import {editField_Controllers} from  './editField.controller';
    import {editField_directive} from './editField.directive';
    var editFieldModule: ng.IModule = angular.module("comp.modules.editField", []);
    editFieldModule.controller("editFieldController", editField_Controllers.EditFieldController);
    editFieldModule.directive("efpEditField", [() => new editField_directive.EditFieldDirective()]);
    export {editFieldModule};