How to create module in angularjs and What is the use of module in angularjs?

How to create module in angularjs and What is the use of module in angularjs?


?
1
2
3
4
5
var app= angular.module("MyApp", []);
//The above (with [] module) is indicate that this a setter function its used for register a module.
var app= angular.module("MyApp");
//The above (without [] module) is indicate that this is getter function and its used for retrieve a previously registered module.
var app= angular.module("MyApp", []);
//The above (with [] module) is indicate that this a setter function its used for register a module.

var app= angular.module("MyApp");
//The above (without [] module) is indicate that this is getter function and its used for retrieve a previously registered module.
Example. The given below explain about basic concept of module.
?
1
2
3
4
5
6
var app = angular.module("MyApp", []).controller("contr1", function(){}); // module MyApp has controller contr1.
var app = angular.module("MyApp").controller("contr2", function(){}); // module MyApp has controllers contr1, contr2.
var app = angular.module("MyApp", []); // module MyApp  registered to this module.
app.controller("contr3", function(){}); // module MyApp has controller contr3 only.
var app = angular.module("MyApp", []).controller("contr1", function(){}); // module MyApp has controller contr1.

var app = angular.module("MyApp").controller("contr2", function(){}); // module MyApp has controllers contr1, contr2.

var app = angular.module("MyApp", []); // module MyApp  registered to this module.
app.controller("contr3", function(){}); // module MyApp has controller contr3 only.
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.