In the preceding code, it is not a good idea to put functional code in the global namespace, which can cause conflicts that are difficult to debug and waste valuable development time. As you might have guessed, the code that is valid for the final product will be the concept of encapsulating our functionality into a unit called module, which is the primary way to define ANGULARJS applications. In the app's module we will include all of the code. An application Keyi contains several modules, each of which contains code for a specific function. The benefits of using modules are obvious:
- Keep the global namespace clean
- Test easier to write
- Easy sharing of code between programs
- Load different parts of code in any order
The declaration format for the module is angular.module (' myApp ', []), passing in two parameters: the first parameter is the name of the module we are creating, and the second parameter is all the injected dependency lists. This method is called setter method, we can also use the same method to reference our module such as Angular.module (' myApp '), that is, getter mode.
The Angular module has some properties that we can view, the Name property returns the module name string that we define, and the requires property contains the list that the module depends on before it is loaded.
ANGULARJS best Practices three----modules