Skip to content
This repository was archived by the owner on Jun 7, 2021. It is now read-only.

Using inject attribute instead of $inject; #100

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"use strict";

import Inject from "./";

import {AbstractController} from "./modules/commons/controllers/abstract.controller";
import IStateService = angular.ui.IStateService;
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<string> = ["$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!");
}
Expand Down
7 changes: 7 additions & 0 deletions src/app/index.ts
Original file line number Diff line number Diff line change
@@ -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";
6 changes: 3 additions & 3 deletions src/app/modules/commons/controllers/abstract.controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"use strict";

import Inject from "../../../";

import IStateService = angular.ui.IStateService;
import ILogService = angular.ILogService;

export abstract class AbstractController {
private logger:ILogService;
private $state:IStateService;

public static $inject:Array<string> = ["$log", "$state"];

public constructor(logger:ILogService, $state:IStateService) {
public constructor(@Inject("$log") logger:ILogService, @Inject("$state") $state:IStateService) {
this.logger = logger;
this.$state = $state;
}
Expand Down
7 changes: 3 additions & 4 deletions src/app/modules/home/components/foo/foo.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"use strict";

import Inject from "../../../../";

import IStateService = angular.ui.IStateService;
import ILogService = angular.ILogService;

import {AbstractController} from "../../../commons/controllers/abstract.controller";

export class FooController extends AbstractController {

// necessary to help AngularJS know about what to inject and in which order
public static $inject: Array<string> = ["$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");
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/home/home.controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"use strict";

import Inject from "../../";

import IStateService = angular.ui.IStateService;
import ILogService = angular.ILogService;

import {AbstractController} from "../commons/controllers/abstract.controller";

export class HomeController extends AbstractController {

public static $inject: Array<string> = ["$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...");
}
Expand Down