Angular 1.x–Finding error in module using small recursion

25 בApril 2016

one comment

Recently, to have an application angular 2.0 ready I’ve divided an angular 1.5 application
to small modules.

Of course this process wasn’t a straight forward one, however finding where there is a missing or
error module was critical, otherwise I’ll get an error message on the main module I have a little to do with.

Therefore, I’ve built a small recursive function, using the module.requires array property (available from v1.2)
, which I want to share:

   1: function getModule(moduleName){ 

   2:  console.log('Getting module ' + moduleName);

   3:  var module = angular.module(moduleName);

   4:  if (!module) {

   5:     consoile.error('Module ' + moduleName + ' was not found');

   6:     return;

   7: }

   8:  for (var i = 0; i < module.requires.length; i++){

   9:      getModule(module.requires[i]);

  10: }

  11: }

This  function goes recursively in the modules tree and prints to the error console of the module it can’t get.

It is also available on the following gist:

https://gist.github.com/ranwahle/306c906e1bd03cef4fb975dd10487496

Enjoy!

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

one comment

  1. איציק עגם26 בApril 2016 ב 22:30

    רן, אחלה כתבה
    תודה רבה וחג שמח!

    Reply