Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to write one JavaScript file containing multiple modules?

It just comes to my mind that most AngularJS (*.js) file I have seen so far only contains one module, and the name of the module is not always the same to the file name.

I would like to know, whether it works by putting multiple modules inside one AngularJS (*.js) file.

Also, how does the server find the correct module name when web page makes a function call? By searching every file in the directory in a brute-forced way?

like image 323
jsh6303 Avatar asked Aug 24 '26 20:08

jsh6303


1 Answers

You can put as many modules as you want in a file (not necessarily best practice though). Angular knows which module to load because you register each module with Angular.

angular.module('myModule', [])

That way it doesn't have to look for modules based on convention.

like image 187
carpenter Avatar answered Aug 26 '26 09:08

carpenter