1.0.0 • Published 10 years ago

angular-controller-decorator v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

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;
1.0.0

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago