1.0.0 • Published 10 years ago
angular-controller-decorator v1.0.0
angular-controller-decorator
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;