diff --git a/src/app/app.controller.ts b/src/app/app.controller.ts index 1c0f8a4891..0d46c78cc3 100644 --- a/src/app/app.controller.ts +++ b/src/app/app.controller.ts @@ -1,5 +1,7 @@ "use strict"; +import Inject from "./"; + import {AbstractController} from "./modules/commons/controllers/abstract.controller"; import IStateService = angular.ui.IStateService; import ILogService = angular.ILogService; @@ -7,10 +9,7 @@ import ILogService = angular.ILogService; // controller export class AppController extends AbstractController { - // necessary to help AngularJS know about what to inject and in which order - public static $inject:Array = ["$log", "$state"]; - - public constructor(logger:ILogService, $state:IStateService) { + public constructor(@Inject("$log") logger:ILogService, @Inject("$state") $state:IStateService) { super(logger, $state); logger.debug("Application bootstrapped!"); } diff --git a/src/app/index.ts b/src/app/index.ts index a2464137ad..ff6309c5a1 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -1,3 +1,10 @@ "use strict"; +export default function Inject(injectable: string): (prototype: ng.IControllerService, method: any, argumentPosition: number) => void { + return function(prototype: ng.IControllerService, method: any, argumentPosition: number): void { + prototype.$inject = prototype.$inject || []; + prototype.$inject[argumentPosition] = injectable; + }; +} + export * from "./app"; diff --git a/src/app/modules/commons/controllers/abstract.controller.ts b/src/app/modules/commons/controllers/abstract.controller.ts index fa52f69956..0aca086c6d 100644 --- a/src/app/modules/commons/controllers/abstract.controller.ts +++ b/src/app/modules/commons/controllers/abstract.controller.ts @@ -1,5 +1,7 @@ "use strict"; +import Inject from "../../../"; + import IStateService = angular.ui.IStateService; import ILogService = angular.ILogService; @@ -7,9 +9,7 @@ export abstract class AbstractController { private logger:ILogService; private $state:IStateService; - public static $inject:Array = ["$log", "$state"]; - - public constructor(logger:ILogService, $state:IStateService) { + public constructor(@Inject("$log") logger:ILogService, @Inject("$state") $state:IStateService) { this.logger = logger; this.$state = $state; } diff --git a/src/app/modules/home/components/foo/foo.controller.ts b/src/app/modules/home/components/foo/foo.controller.ts index 70528095b6..5d8994fc7e 100644 --- a/src/app/modules/home/components/foo/foo.controller.ts +++ b/src/app/modules/home/components/foo/foo.controller.ts @@ -1,5 +1,7 @@ "use strict"; +import Inject from "../../../../"; + import IStateService = angular.ui.IStateService; import ILogService = angular.ILogService; @@ -7,10 +9,7 @@ import {AbstractController} from "../../../commons/controllers/abstract.controll export class FooController extends AbstractController { - // necessary to help AngularJS know about what to inject and in which order - public static $inject: Array = ["$log", "$state"]; - - public constructor(logger:ILogService, $state:IStateService) { + public constructor(@Inject("$log") logger:ILogService, @Inject("$state") $state:IStateService) { super(logger, $state); logger.debug("Foo component loaded"); } diff --git a/src/app/modules/home/home.controller.ts b/src/app/modules/home/home.controller.ts index b575cf269f..80ab8646d1 100644 --- a/src/app/modules/home/home.controller.ts +++ b/src/app/modules/home/home.controller.ts @@ -1,5 +1,7 @@ "use strict"; +import Inject from "../../"; + import IStateService = angular.ui.IStateService; import ILogService = angular.ILogService; @@ -7,9 +9,7 @@ import {AbstractController} from "../commons/controllers/abstract.controller"; export class HomeController extends AbstractController { - public static $inject: Array = ["$log", "$state"]; - - public constructor(logger:ILogService, $state:IStateService) { + public constructor(@Inject("$log") logger:ILogService, @Inject("$state") $state:IStateService) { super(logger, $state); logger.debug("Home controller loaded..."); }