Skip to content

Instantly share code, notes, and snippets.

@theuntitled
Last active March 30, 2016 12:48
Show Gist options
  • Save theuntitled/bfc79236ebd5af74d0bb9d1cb47b89d5 to your computer and use it in GitHub Desktop.
Save theuntitled/bfc79236ebd5af74d0bb9d1cb47b89d5 to your computer and use it in GitHub Desktop.
TypeScript AngularJS 1.x $inject example
module Dev.Controllers {
export class DemoController {
static $inject: string[] = ["$scope"];
constructor($scope: any) {
// ...
}
}
}
module Dev.Directives {
export class DemoDirective implements ng.IDirective {
scope = true;
restrict = "A";
require = "?ngModel";
private $location: ng.ILocationService;
constructor($location: ng.ILocationService) {
this.$location = $location;
// ...
}
link = (scope: ng.IScope, element: JQuery, attrs: ng.IAttributes) => {
// ...
};
static factory(): ng.IDirectiveFactory {
const directive = ($location: ng.ILocationService) => new DemoDirective($location);
directive.$inject = ["$location"];
return directive;
}
}
}
module Dev.Filters {
export class DemoFilter {
static $inject = ["$sce"];
static filter($sce: ng.ISCEService) {
return (value: string) => {
return $sce.trustAsHtml(value);
};
}
}
}
var app = angular.module("demo", [
"ng"
]);
app.controller("DemoController", Dev.Controllers.DemoController);
Dev.Filters.DemoFilter.filter.$inject = Dev.Filters.DemoFilter.$inject;
app.filter("demoFilter", Dev.Filters.DemoFilter.filter);
app.directive("DemoDirective", Dev.Directives.DemoDirective.factory());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment