angular-controller-decorator

1.0.0 • Public • Published

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 'install angular-controller-decorator';
import AppController from './controller';
 
angular.module('app', [])
    .controller( decorator(AppController) );
// in ./controller.js
 
class AppController {
    static $inject = ['$rootScope', '$http'];
 
    constructor ($rootScope, $http) {
        // code
    }
 
    setGlobalConfig(config) {
        // you can get dependencies throught `this.injections` property
        let { $rootScope } = this.injections;
        $rootScope.config = config;
    }
 
    getConfig(url) {
        let { $http } = this.injections;
 
        return $http.get(url);
    }
}
 
export default AppController;
 

Readme

Keywords

Package Sidebar

Install

npm i angular-controller-decorator

Weekly Downloads

4

Version

1.0.0

License

MIT

Last publish

Collaborators

  • dolphin_wood