Spectacular Angular Dependency Injection isolated as a library. Working in Browser and Node environments
npm install ng-di
Once installed, start using it
var di = require('ng-di');
di.module(...);
di.injector(...);
Download the production version or the development version.
You can also download a ZIP version with both flavours and the mocks helper.
In your web page:
<script src="dist/ng-di.min.js"></script>
<script>
di.module(...);
di.injector(...);
</script>
This library simply isolates AngularJS dependency injection, exposing its module API as part of it.
All the DOM management has been removed, and makes this library the ideal artifact for using Javascript Dependency Injection in javascript only apps, libraries...
It's available as di
instead of angular
The public API, considered stable, is(*):
(*)As this library is framework agnostic, the AngularJS concepts and module API methods module.directive
and module.controller
are NOT available inside the Module API
Other non documented utility methods here are for private usage, and can be removed
Please, refer to Angular Documentation on this topics, as ng-di exposes them as-is.
You can go to the examples folder to see how to use in node and browser
The tests provided have been written in jasmine, and are executed in browser with Karma Runner and in Node with jasmine-node
For your convenience on writing testable code using ng-di, as well as in angular, two utility functions are exposed
mock.module(...);
mock.inject(...);
You can read through code documentation or learn by watching examples
var mock = require('ng-di/mock'),
//mock.module and mock.inject are available
Include the mock helper in your test flow.
<script type="text/javascript" src="mock.js"></script>
<!-- mock.module and mock.inject are available -->
After cloning, the repository...
Install all dependencies
npm install
ng-di uses grunt 0.4.x for building the browser version and for testing. You will need to have installed grunt-cli as global
Pass all test in browser and node.
Relies on Karma and assumes a PhantomJS(*) browser installed on your machine
grunt test
Build the browser version
Creates all browser compatible code on /dist directory
grunt build
Test and build
grunt
(*) After installing PhantomJS, add the executable to your path
#Add phantomJS to MacOSX PATH by editing ~/.bash_profile
export PHANTOMJS_BIN=/Applications/phantomjs-1.9.0-macosx/bin/phantomjs
The goal behind this project is closing the gap between the browser and node environments for developing testable libraries and applications that could be used in both environments.
Just provide different implementations for those environment dependant code (Browser XMLHttpRequest vs. Node http) and reuse all the application code
ng-di isolates you from the dependency injection in environments, but you will have to deal with the CommonsJS/AMD/no-module problem by yourself. Ideas are always welcome!
ng-di uses semantic versioning
- Expose annotate function
- FIX compatibility with mocha in mocks
- Completely rewrite internals using commonsJS module.
- Adding mocks for both environments
- $utils is not exposed anymore.
- Module 'di' is not registered by default
- Removed lots of utility functions from being accesible. See utils for details.
- Requiring in node does not need to recall
di
. Use:var di = require('ng-di');
- Adding more utilities functions to the code
- Adding more utilities functions to the code
- new service in module
di
exposing$utils
functions
- First approach
This work is more-than-heavily based on AngularJS Dependency injection. All credits must go to the Angular Developers Licensed under the MIT license.