fourth fourth - 1 month ago 15
Node.js Question

about module in the angular

I am new in this field and reading about one project code. Here are two file.
https://github.com/PatrickO10/meetUp/tree/master/app/dashboard
In the first file:

(function(){
'use strict';
angular.module('app.dashboard', ['firebase']);
})();


In the second file, similiar code appears again

https://github.com/PatrickO10/meetUp/blob/master/app/dashboard/dashboard.controller.js#L4-L6

I see many code write like
var app=angular.module(...)
, if you write in way of first file, how could you use the module again? and why you write it in this way?

I also want to know why you write the first file here, why don't you put all things in the second file.

Thanks.

Answer

When you define your module in angular, you have to define an array as second parameter with the list of modules your module depend on (or an empty array if is not depending on anything).

When you use your module in angular, you skip this second parameter.

These are the two cases in your code.

You could put everything in same file, but it is considered a general good practice to keep individual files for different controllers/services/directives (or even the definition of the module).