https://github.com/nnmrts/controllerhandler
ControllerHandler simplifies controller initialization in AngularJS
https://github.com/nnmrts/controllerhandler
Last synced: 11 months ago
JSON representation
ControllerHandler simplifies controller initialization in AngularJS
- Host: GitHub
- URL: https://github.com/nnmrts/controllerhandler
- Owner: nnmrts
- Created: 2017-05-06T08:35:43.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-01-13T07:54:40.000Z (over 5 years ago)
- Last Synced: 2025-04-07T18:19:59.463Z (about 1 year ago)
- Language: JavaScript
- Size: 478 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ControllerHandler
ControllerHandler is a small JavaScript constructor function for AngularJS.
It simplifies the process of declaring controllers and makes dependency injection a little bit easier.
---
## Example
Normal controller declaring compared to that with ControllerHandler:
Vanilla:
```js
// MyController
MyControllerFunction = function ($scope, $timeout, $window, $http, $q) {
// $scope.stuff ...
};
MyApp.controller("MyController", ["$scope", "$timeout", "$window", "$http", "$q", MyControllerFunction]);
// MyOtherController
MyOtherControllerFunction = function ($scope, $timeout, $window, $http, $q) {
// $scope.stuff ...
};
MyApp.controller("MyOtherController", ["$scope", "$timeout", "$window", "$http", "$q", MyOtherControllerFunction]);
```
Using ControllerHandler:
```js
// MyController
MyControllerFunction = function ($scope, $timeout, $window, $http, $q) {
// $scope.stuff ...
};
MyControllerHandler = new ControllerHandler({
app: MyApp,
name: "MyController",
code: MyControllerFunction,
debug: true
});
// MyOtherController
MyOtherControllerFunction = function ($scope, $timeout, $window, $http, $q) {
// $scope.stuff ...
};
MyOtherControllerHandler = new ControllerHandler({
app: MyApp,
name: "MyOtherController",
code: MyOtherControllerFunction
});
```
You can find an example site where ControllerHandler is used in the example folder.
## Features
ControllerHandler manages inline dependency injection for you, so you don't have to write down your depencies twice but at the same time your app still works when minified. Also, it gives you a nice little object to configure your controller and not some confusing arrays or parentheses.
Another feature is the `debug` option. If it is set to true, you can see all information about your controller(s) in your browser console.
## Docs
Download this repository and open the index.html in the docs folder, there is everything explained in detail about how to use ControllerHandler.