Last active
August 29, 2015 14:24
-
-
Save LordZardeck/47e95b1d0d3370fa7647 to your computer and use it in GitHub Desktop.
AngularJS TypeScript decorators
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
function DecorateAngularObject(module: string, target: Object, type: string, className?: string): void { | |
switch (type) { | |
case "config": | |
case "run": | |
angular.module(module)[type](target); | |
break; | |
default: | |
angular.module(module)[type](className, target); | |
break; | |
} | |
} | |
function Controller(module: string, className: string) { | |
return (target: Function) => DecorateAngularObject(module, target, "controller", className); | |
} | |
function Directive(module: string, className: string) { | |
return (target: Function) => DecorateAngularObject(module, target, "directive", className); | |
} | |
function Service(module: string, className: string) { | |
return (target: Function) => DecorateAngularObject(module, target, "service", className); | |
} | |
function Factory(module: string, className: string) { | |
return (target: Function) => DecorateAngularObject(module, target, "factory", className); | |
} | |
function Run (module: string) { | |
return (target: Function) => DecorateAngularObject(module, target, "run"); | |
} | |
function Config (module: string) { | |
return (target: Function) => DecorateAngularObject(module, target, "config"); | |
} | |
function Inject (...args: string[]) { | |
return (target: any) => { | |
(<Function>target).$inject = args; | |
return target; | |
}; | |
} |
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
@Controller("app.store", "StoreItemDetailController") | |
@Inject("$scope", "$stateParams") | |
class StoreItemDetailController { | |
constructor($scope, $stateParams) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment