How to add dependencies in a module already initialized in AngularJs?

1

I usually use AngularJS with a framework where I have a Javascript script for each page of my application.

The main dependencies and project settings I define in a app.js file, which is used on all pages.

More or less like this:

// 'js/app.js'

angular.module('app', ['ngAnimate', 'ui.validate'])


// 'js/usuarios/listar.js'

angular.module('app').controller('UsuariosController', function () {
      // resto do código
})

That is, I always add to the existing module app a functionality according to the page that I load (I'm not using SPA).

So, I need to load a specific dependency for a particular script into the app module.

In the case of script js/usuarios/editar.js , I need to add ngFileUpload .

I would not like to be added to my default app.js , since I will not upload files on all pages of my application, but only in that specific where I use js/usuarios/editar.js .

Is it possible to add a dependency on an angle module that has already been initialized?

    
asked by anonymous 28.08.2018 / 20:41

1 answer

2

Translation of this answer

I use the following method and it works fine with me:

var app = angular.module("myApp", []);

angular.module("myApp").requires.push('ngResource');

If you need to place more than one dependency on the same module, you can extend the push ()

angular.module("myApp").requres.push('dep1', 'dep2', 'dep3');
    
28.08.2018 / 21:26