Introduction of the Angularjs module class and its modular dependencies

Source: Internet
Author: User

After the study we will follow a controller to manage a view, a single route corresponding to a view of the principle, so the controller code is not directly written into the index.html.

We will apply it to the powerful modules in angular.js, such as routing, service, filters, instructions and so on.

So this blog is very necessary to the various modules between the dependencies, definitions, use and other issues to state.

So how did the angular.js load start up?

<! DOCTYPE html>

This is a very simple index.html page we did on the previous article.

After starting the service, which main method does the Angular.js start with?

In fact, after the browser opened index.html, angular.js there is no Main method, angular.js through the module instead of main, the module through the declaration to describe the dependencies, as well as the assembly and start-up between the modules.

The ng-app instruction tells Angular.js to use the Yijiebuyi module to launch the app.

The module starts through 2 stages.

1.Config code,Angularjs will connect and register all data sources, and uncertain services or data will not be injected.

2.Run code, launch your app, start execution after the syringe is created, and only instances and constants can be injected into the run code block, where the run code block resembles the main method in other languages.

Modules can instantiate controllers, directives, filters, and services through APIs.

The common APIs are as follows:

1.config (CONFIGFN)

With this approach, you can do some registration work that needs to be done when the module is loaded.

such as the Ui.router module, can be fully registered in this method.

2.constant (name, object)

This method runs first, so you can use it to declare constants throughout the application, and make them available in all Configurations (config methods) and instances (all subsequent methods, such as controller, service, and so on).

3.controller (Name,constructor)

Its basic function is to configure the controller conveniently for later use.

4.directive (Name,directivefactory)

You can use this method to create directives in your app.

5.filter (Name,filterfactory)

Allows you to create a named Angularjs filter, as discussed in the previous section.

6.run (INITIALIZATIONFN)

You can use this method if you want to perform certain actions after the syringe is started, and these actions need to be performed before the page is available to the user.

7.value (Name,object)

Allows the injection of values throughout the application.

8.factory (NAME,FACTORYFN)

If you have a class or object, you need to give it some logic or parameters before you can initialize it, then you will be able to use the factory interface here. Factory is a function that is responsible for creating some specific values (or objects).

9.service (Name,object)

The difference between factory and service is that factory invokes the function passed to it directly and returns the result of execution, and the service uses the "new" keyword to invoke the constructor passed to it, and then returns the result.

10.provider (NAME,PROVIDERFN)

Provider is the most complex part of these methods (obviously, it is also the best configurable part).

Provider binds both the factory and the service, and you can also enjoy the benefits of configuring the provider function (that is, the Config block) before the injection system is ready to complete.

Introduction to the Angularjs module class and its modular dependencies

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.