ng-lazy-module

Angular modules grew lazy
Homepage:
1 person uses it
Author: 12109873?v=3 ex-machine
Submitted by: 2905949?v=3 bisubus

ng-lazy-module

Does the same things you would normally do with angular.module('...') but in a leisurely manner.

Description

This tiny zero-overhead Angular patch provides a set of lazy.… methods for each Angular module that reflects module's own methods but can be used after the modules have been bootstrapped.

E.g. a new directive angular.module('...').lazy.directive(...) can be defined within existing app components and compiled then.

The exceptions are config and run which cannot be used to define new config/run blocks when the respective phases are over.

Install

NPM

npm install --save ng-lazy-module

Bower

bower install --save ng-lazy-module

Usage

ng-lazy-module.js is loaded after angular.js and before Angular modules.

Let the example speak for itself.

Pitfalls

Precedence

lazy.run won't be available before run phase and the rest of lazy methods won't be available before config phase.

The things can become too messy and complicated when there are several lazy modules that depend on each other. Although solid promise chains may minimize the possibility of having missing dependencies and maintain app design in a good shape.

Lazy config

lazy.config can be used to get to service providers even when config phase is over. Existing service instances may or may not be affected with changes to corresponding providers. Replaced provider $get property takes effect only if the service hasn't been instantiated yet.

Decoration

lazy.decorator was introduced as well, but its usage could be justified rarely. It won't have an effect on the services which were injected into advance module components and thus, instantiated (as the example shows).

Chaining

lazy.… methods return another lazy object, not module. The proper chaining syntax for lazy components is

angular.module('...').lazy

.directive(...)

.controller(...);

comments powered by Disqus
This page was last updated about 2 years ago.