Giter Club home page Giter Club logo

ng-amd's Introduction

ng-amd

An ng-amd plugin for loading and injecting modules into an angular application.

What is it?

ng-amd is a set of two AMD plugins for RequireJS. These allow RequireJS to act as a form of Service Location, with angular controlling the Dependency Injection.

Usage

Usage is fairly simple.

Add the plugins to your config file, with whatever name you want to give them. If installed through bower, for example it might similar to below.

'ng': '../../bower_components/ng-amd/src/ng',
'ng-module': '../../bower_components/ng-amd/src/ng-module'

ng-module!

ng-module!path/to/module will load the given dependency as a module, into angular. Any dependencies loaded with ng-module will be made dependencies (module.requires) of the one that loaded it. And so on and so forth.

ng!

ng!path/to/service will load the given dependency as a service, into angular. Currently it supports services in various forms...

  • ['$parse', '$compile', function($parse, $compile)] (loads as a factory)
  • function($parse, $compile) {}.$inject = ['$parse', '$compile']; (loads as a factory)
  • ['$parse', '$compile', { $get: function($parse, $compile) }] (loads as a provider)
  • { $get: function($parse, $compile) {}.$inject = ['$parse', '$compile'] } (loads as a provider)
  • function(module) {} -- The one gotcha here, you cannot by default use the inferred dependency syntax. If we find a function, with no dependencies, then we will give you the module. This way you can register controllers, directives, values and constants.

Anything loaded with ng! will first try to find the module it is attached too via it's path. If it can't be inferred through the path it may be provided...

With a pipe on the dependency itself ng!path/to/service|moduleName

With a RequireJS config setting

requirejs.config({ config: { 'ng': { module: 'moduleName' } } })

If those all fail, it will default simply to 'app'

Angular must be manually bootstrapped, using ngApp is not easily possible, if loading through RequireJS.

define(['angular', 'ng-module!app'], function (angular, app) {
    angular.bootstrap(document, ['app']);
});

Roadmap

  • Injecting dependencies after angular has loaded, to support things like loading controllers, directives on the fly depending on a given route.
  • More comprehensive Unit Testing

ng-amd's People

Contributors

david-driscoll avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.