Question

var demoApp = angular.module( 'demoApp', [] );

Why didn't the angular team simply choose to do:

var demoApp = angular.module ([]);

instead?

Was it helpful?

Solution

You don't have to if you don't want to. You can write any of the following and they're the same thing

var demoApp = angular.module('demoApp', []);
var diffApp = angular.module('demoApp', []);
angular.module('demoApp', []);

The variable you assign it to can be named whatever you want it to be, but the name you pass in to the module function is the name that angular will give it internally. That name must be the same name you use to retrieve it later. So for instance, you could do the following

angular.module('demoApp', []);
angular.module('demoApp').controller('ctrl', function(){ ... });

And that is exactly the same as doing

var myApp = angular.module('demoApp', []);
myApp.controller('ctrl', function() { ... });

When you provide the module function a second parameter, you are defining a new module. If you just provide it with a string, you are asking angular to retrieve you a module.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top