Last active
March 30, 2016 12:48
-
-
Save theuntitled/bfc79236ebd5af74d0bb9d1cb47b89d5 to your computer and use it in GitHub Desktop.
TypeScript AngularJS 1.x $inject example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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