This snippet illustrates the creation of a module in AngularJS.
var app = angular.module('myApp', ['ngRoute']);
The name myApp
represents the application and is essentially a string.
Within the square brackets, like [ngRoute]
, are the modules to be injected, following the concept of dependency injection. Common modules include ui.bootstrap
, restangular
, ui.select
, among others.
A couple of points worth noting:
- Make sure not to confuse this syntax with the module referencing syntax (minus the square brackets):
Definition of Module
angular.module('myApp', []);
Referencing a Module
angular.module('myApp');
- It is generally recommended to directly define the module instead of assigning it to a variable, as demonstrated by:
Definition of Module
angular.module('myApp', []);
rather than
var app = angular.module('myApp', ['ngRoute']);
To delve deeper into best practices, you can refer to Papa John's style guide.
https://github.com/johnpapa/angular-styleguide
I trust this information proves helpful. :)