i have a problem regarding the angular dependency injection mechanism. I have written a directive in a standalone module, that does some neat things on a datatable. I'm using TypeScript and my directive looks as follows:
export class MdListControls implements angular.IDirective {
public templateUrl = "/app/templates/mdListControls.html";
public static instance(): any {
return new MdListControls();
};
public restrict = 'E';
public transclude = true;
public replace = true;
public scope = {
grid: '=',
};
public controller = "mdListControlsController"
public controllerAs = "vm";
public link = function (scope: angular.IScope, element: angular.IAugmentedJQuery, attrs: angular.IAttributes) {
};
}
My Controller looks something like this:
export class MdListControlsController {
static $inject = ['scope']
constructor($scope: angular.IScope){
//Setup the constructor
}
//Here goes the controller Logic
}
I'm registering the directive and the controller at a new module as follows:
angular.module("base.directives.mdListControls", [])
.controller("mdListControlsController", MdListControlsController)
.directive("mdListControls", function () { return MdListControls.instance() });
However, once I run the app, I get the following error once the directive shall be loaded:
Argument 'mdListControlsController;' is not a function, got undefined
This doesn't quite look like a problem with dependency injection at first. But when I register the controller on the application itself (which gets injected the "base.directives.mdListControls" Module) like so
app.controller("mdListControlsController", MdListControlsController);
everything works fine and the controller gets injected properly into the directive.
Does anyone know what I'm doing wrong here? Thanks for your help!