I came across a post on Stack Overflow discussing the best practices for declaring AngularJS modules. Despite reading it, I am still unsure about the most effective way to separate and declare angularJS files for modules, controllers, services, etc.
I have learned that encapsulating controllers and services in IIFEs is recommended as it prevents them from being used out of scope. Additionally, separating controllers and modules into distinct files is advised for better organization.
My question pertains to how to declare the module in its own file:
myModule.js
Should I leave it at global scope so it can be accessed by all components, like this:
var app = angular.module("myApp", []);
Alternatively, is there a way to wrap it in an IIFE to avoid global scope while still making it accessible to other files?