我正在尝试将 Javascript 角度模块转换为 TypeScript。目前我正在使用 ES6 模块加载器。并尝试将每个模块一一转换。我确实将一个模块转换为 TypeScript,但是 ES6 加载器无法加载控制器和指令时遇到问题。
这是我的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]);
这里是我Angular module
写的TypeScript
。
var editFieldModule: ng.IModule = angular.module("comp.modules.editField", []);
export {editFieldModule};
这是我的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);
}
这是我的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()]);
}
我可以看到我的模块正在加载,但控制器和指令从未注册,也根本没有下载。谁能告诉我我在哪里做错了。