https://github.com/idiotwu/angular-controller-decorator
A decorator function for angular controllers that helps you inject dependencies to prototype method!
https://github.com/idiotwu/angular-controller-decorator
Last synced: 7 months ago
JSON representation
A decorator function for angular controllers that helps you inject dependencies to prototype method!
- Host: GitHub
- URL: https://github.com/idiotwu/angular-controller-decorator
- Owner: idiotWu
- License: mit
- Created: 2015-10-13T10:15:20.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-13T14:17:34.000Z (almost 10 years ago)
- Last Synced: 2025-02-20T15:05:07.875Z (8 months ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## angular-controller-decorator
[](https://nodei.co/npm/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
```javascript
// in index.jsimport decorator from 'angular-controller-decorator';
import AppController from './controller';angular.module('app', [])
.controller( 'AppController', decorator(AppController) );
``````javascript
// in controller.jsclass 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;
```