Spectacular Angular Dependency Injection for Javascript isolated as a library. Working in Node and Browser

Module License: MIT

Added by: Sam Deering





Stars: 37

Watchers: 37

Forks: 10

Module Description


Spectacular Angular Dependency Injection isolated as a library. Working in Browser and Node environments

Current Canary Version 0.1.1 Build Status

Status: STABLE API - UNSTABLE Code sources location - All Test passing

  • Recommended *

Current Version 0.0.4

Status: UNSTABLE API - UNSTABLE Code sources location - No test

  • Not recommended *

Getting Started

On the server

Install the canary version module with:

npm install [email protected]


npm install [email protected]

Or the pre-development one

npm install ng-di

Once installed, start using it

var di = require('ng-di');

In the browser

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>


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


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


(*) 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 

Aim of this project

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!

Release History

ng-di uses semantic versioning


  • 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.

Bitdeli Badge

Module stats last updated: 2017-12-11 15:00:02

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!