+91 9701000415 info@nbits.in

angularjs modules
16 Apr 2018

Angular JS Modules

Angularjs Modules:

angular modules

           A module is a collection of code for an independent piece of functionality .In angularjs we use module as a container for the different parts of our app like controllers,directives,services etc.Angularjs recommends us to organize our code into modules. Each module can have its own parts of code. Consider the example of an ecommerce application. We can divide the application into independent set of functionality like payment,cart,product,user and all of these can represent a module. This implies that we can create a payment module,user module and so on.

How can create a Module?

Simple, just call the angular.module function as shown below Var userModuleReference = angular.module(“userModule”,[])

Note that we have got a reference returned of the module instance in the variable user Module Reference. The second parameter to the .module function is a comma separated value of modules required for the user Module. In this example the user module does not depend on any module so we can write the empty square bracket there.

Main Module:

If our application is a collection of many modules, then we also need a main module from where we will initialize our application. Its just like the main method of Java, or c,c++.To initialize our main module, we need to give the value of ng-app attribute with the value of the main module. Lets say our main module is my App.We can give a reference to myApp module in <div ng-app=”myApp”>. This is what bootstraps the app using our module.

Retrieving module:

     If any part of script we want to retrieve a particular module, we need to call the module method without the module dependencies array.The code var myModule = angular.module(‘myModule’,[]) creates the module and returns the reference. But var myModule = angular.module(‘myModule’) returns the reference of already created module.Note that if the module is not created before, the the above line with throw error.

       NBITS provides the Best Angular training by real time experts.It is the best software training institute in Hyderabad.It can provides the training through the online and offline training.In the training period conduct the two real time projects.In this one project is run in training period and another one is assignment for you.The trainer has 11+ years experience the ui development field.If you any queries can contact our team 9701000415.


Leave a Reply