The best AngularJS module Tutorial In 2024, In this tutorial you can learn Create a module,Add Controller,AngularJS examples,Add instructions,AngularJS examples,Modules and controllers included in the JS file,AngularJS examples,myApp.js,myCtrl.js,Function will affect the global namespace,When loading the library?,AngularJS examples,
Module defines an application.
Module is a container in different parts of the application.
Controller module is a container application.
The controller usually belong to a module.
You can create a module by AngularJS ofangular.module function:
"MyApp" parameter corresponds to the execution of the application HTML elements.
Now you can add a controller instructions, filters, etc. in AngularJS applications.
You can useng-controller instructions to add applications Controller:
You can AngularJS Controllers learn more knowledge about the controller section.
AngularJS provides many built-in commands, you can use them to add functionality to your application.
Complete instructions can be found in the contents of AngularJS reference manual .
In addition, you can use the module to add your own instruction applications:
You can AngularJS directives learn more knowledge about instruction section.
Typically AngularJS application module and the controller is included in the JavaScript file.
In the following examples, "myApp.js" contains the definition of the program application modules, "myCtrl.js" file contains the controller:
In the module definition [] parameter is used to define module dependencies. Brackets [] indicates that the module does not rely on, if there is dependency, then will depend on the module name written in parentheses. |
JavaScript should avoid using global functions. Because they can easily be covered with another script file.
AngularJS module scope so that all functions in the module, to avoid the problem.
In our example, all AngularJS HTML document libraries are loaded in the head. |
For HTML applications is generally recommended to all scripts are placed in the bottom of <body> element.
This will increase the page loading speed, because HTML is not subject to load script to load.
In our multiple AngularJS example, you will see AngularJS library is loaded in the <head> area of the document.
In our example, AngularJS in the <head> element is loaded, because the call to angular.module only be carried out after the completion of loading the library.
Another solution is to load AngularJS library <body> element, but must be placed in front of your AngularJS script: