This syntax defines a module.
var app = angular.module('myApp', ['ngRoute']);
myApp this is the name of the app, this is just a string.
[ngRoute] within the square brackets are the modules you'd like to inject (the notion of dependency injection). Some common ones you might have seen or will see include ui.bootstrap, restangular, ui.select etc.
Two things worth mentioning:
- Please be careful to not mix it up with the module referencing syntax (without the square brackets):
Module definition
angular.module('myApp', []);
Module referencing
angular.module('myApp');
- Usually, it's better practice to simply write the module definition out instead of assigning it to a variable, as in
Module definition
angular.module('myApp', []);
instead of
var app = angular.module('myApp', ['ngRoute']);
You can have a look at Papa John's style guide for more information.
https://github.com/johnpapa/angular-styleguide
Hope this helps. :)