Skip to content

A decorator function for angular controllers that helps you inject dependencies to prototype method!

License

Notifications You must be signed in to change notification settings

idiotWu/angular-controller-decorator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-controller-decorator

NPM

This is a small decorator function that helps you inject dependencies into angular controllers' prototype method.

Install

npm install angular-controller-decorator --save

Usage

// in index.js

import decorator from 'angular-controller-decorator';
import AppController from './controller';

angular.module('app', [])
    .controller( 'AppController', decorator(AppController) );
// in controller.js

class AppController {
    static $inject = ['$rootScope', '$http'];

    constructor ($rootScope, $http) {
        this.getConfig('http://example.org')
            .then(this.setGlobalConfig);
    }

    setGlobalConfig(config) {
        // you can get dependencies through `this.injections` property
        let { $rootScope } = this.injections;
        $rootScope.config = config;
    }

    getConfig(url) {
        let { $http } = this.injections;

        return $http.get(url);
    }
}

export default AppController;

About

A decorator function for angular controllers that helps you inject dependencies to prototype method!

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published