ANGULARJS best Practices three----modules

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.