Reputation: 163
var demoApp = angular.module( 'demoApp', [] );
Why didn't the angular team simply choose to do:
var demoApp = angular.module ([]);
instead?
Upvotes: 0
Views: 73
Reputation: 4398
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.
Upvotes: 1