Using static strings in TypeScript for AngularJS to inject dependencies


module tasks {

    export class TasksConfiguration {

        //id of the configuration used for referencing or defining
        public static named = 'tasksConfig';

        public static values: ApplicationConfiguration = {
            appId: 'demo.tasks',
            appName: 'App_Name_Tasks',
            appCategory: 5,
            rootUrl: '/tasks'
        };
    }

    angular.module('Demo')
        .constant(TasksConfiguration.named, TasksConfiguration.values);
}

module tasks {

    export class TasksController {

        //name of the controller used for referencing or defining this controller
        public static named: string = 'tasksController';
        public static templateUrl: string = 'apps/demo/tasks/tasks.tpl.html';

        //dependencies to other services etc., referenced in the constructor
        static $inject: string[] = ['tasksConfig'/*TasksConfiguration.named*/];

        //constructor getting injected dependency instances
        constructor(appConfig: ApplicationConfiguration) {
        }

    }


    angular
        .module('Tasks', [])
        .controller(TasksController.named, TasksController);
}



 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s