angular-deferload

AngularJS service for callback after module is ready. It is very required when your module needs some ajax request data.

Added by: Sam Deering

GitHub

Repository

bossbyte/angular-deferload

Stats

Stars: 0

Watchers: 0

Forks: 0

Module Description

deferload

AngularJS service for callback after module is ready. It is solution when your module needs some ajax request data and another modules depend on it.


angular.module('your_module').run(function($deferload){
   
   $deferload.module('lazy_module').ready(function(){
      
      //here code after module lazy_module is ready so all ajax reuests was made!
   });
   
});

1. Info

DeferLoad solves problem with loading needed data. Imagine your module needs some basic data from server, adding this data by html or by init global script variables is not clean solution, better is to load this data by ajax requests and DeferLoad allows you to run callback after module is ready.

2. Install

Install by bower - bower install angular-deferload or copy deferload.js to your project

3. Add to your app

Adding is very simple:

angular.module('yourapp',['deferload']); 

4. Using

In your module has ajax requests you should use deferdata promises, you can use it by addings functions or by create defer as name and resolve it on another place.

Example set module to be ready after run some functions:

angular.module('your_lazy_load_module').run(function($deferload){
   
    var dl=$deferload.module('your_lazy_load_module');
   
    //adding methods
    dl.add(function(defer){
        //some code
        defer.resolve();
    }).add(function(defer){
        //some code
        defer.resolve();
    });
    
    //you can create defer and use it in another place
    dl.add('defer1');
    
});

//use in module directive
angular.module('your_lazy_load_module').directive('example',function($deferload)){

    return {
      restrict: 'E',
      link: function ($scope, element) {
          
          //resolve promise when directive is rendering in view
          $deferload.module('your_lazy_load_module').get('defer1').resolve();
      }
    
    }

});

After that You can use this deferred module in another module and be sure that we have all critical data:


angular.module('tipical_module').run(function($deferload){
   
   $deferload.module('your_lazy_load_module').ready(function(){
      
      //here all data from your_lazy_load_module are ready to use
   });

});

Module stats last updated: 2015-04-19 02:41:18

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!