Proficient in Angularjs reading notes (2)

Source: Internet
Author: User

AngularJS Crash view

Because ANGULARJS relies on the browser to parse the template, make sure the template is valid HTML. In particular, be careful about closing the HTML tags (unclosed labels do not produce any error messages, but do not render the view correctly). AngularJS can work well under a valid DOM tree.

AngularJS expands the vocabulary of the HTML (adding new attributes or HTML elements and tells the browser how to interpret them), similar to creating a domain-specific language based on HTML (domain-specific language, DSL), and instruct the browser how to understand it. Therefore, often hear Angularjs "teaches the browser new tricks" the saying.

AngularJS advocates declarative UI architecture. In practice, this means that the template focuses on describing the desired effect, not its implementation.

Modules and Dependency Injection

AngularJS defines the global namespace angular for itself, which provides a variety of functions and a number of convenient functions, module is one of them. Module plays the role of a container for Angularjs managed objects (controllers, services, etc.).

Defining a new module requires passing in a name as the first parameter of the calling module, while the second parameter expresses what other modules the module depends on.

The module is defined so that it can be told that ANGULARJS exists, as long as the Ng-app property is assigned a value.

<!--the next thing, actually I didn't understand, first briefly record it--

Collaboration objects

AngularJS organizes objects with modules. Objects that can be registered on a module are not limited to ANGULARJS objects (controllers, filters, etc.), but also any object that the developer customizes.

Module mode is useful for organizing code, but AngularJS goes a little further. In addition to registering objects in a module, it can also declare the interdependencies of these objects.

As mentioned earlier, $scope objects are mysteriously injected into the controller. In fact, this is because the controller declares that it needs $scope, so Angularjs will create and inject it. The dependency management system can summarize this: "To work, I need a dependency (collaboration object): I don't know where it came from, and I don't know how it was created. I only know I need it, so please provide it for me. ”

Registration Services

AngularJS Only connect to the objects they know. Therefore, the first step in the access dependency injection mechanism is to register the object on the module. Instead of registering an instance of an object directly, we throw the schema created by the object to the dependency injection system, and then Angularjs explain the scenarios to initialize the objects, connect them later, and finally become a running application.

AngularJS's $provide service can register different object creation scenarios. The $injector service then interprets these scenarios to generate complete and usable object instances (all dependencies have been resolved).

You can register the constructor with the service method, or you can use the factory method, which is more flexible than the service.

All of the registration methods described above are the special types of the most common method provider.

Life cycle of the module

ANGULARJS supports a variety of object creation scenarios, and provider is a common method in which you can configure an object instance before it is created. To support Provider,angularjs, divide the lifecycle of a module into two phases:

    • Configuration phase: Collects object creation scenarios and configures them.
    • Run phase: Performs all initialization logic

Services in ANGULARJS applications cannot have duplicate names, and services in the parent module override the same name service in the submodule.

<!--

Fiber Sharp
Source: http://www.cnblogs.com/beginner2014/p/5169150.html
This article is copyrighted by the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link. Thank you for your cooperation.

-

Proficient in Angularjs reading notes (2)

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.