ANGULARJS Study Notes

Source: Internet
Author: User

Recently changed the work, the new environment, the main push AngularJS4, learn other, read the Angularjs tutorial, prepared.
The notes are based mainly on ANGULAR2, where the views are only current, and perhaps a fuller view after the formal project.

1. Advantages of ANGULARJS

1) The binding method of HTML elements and the data passing on the page are regulated, all the operations of the page elements are confined to the frame, and processed with the specified grammatical structure.
2) separate front-end processes, dedicated to handling page interactions that do not involve server-stored data, divert the load from the original back-end process on the server.

Angularjs with a sound framework to the different developers of the DOM, jquery and other understanding, all business code is based on the same operating environment, perhaps the details will still exist in different programming styles, but does not affect the similarity of the global structure, the long-term maintainability of the code has been greatly improved.
At present, such a heavy framework, more suitable for team development, for personal projects are overqualified, the cart before the horse.

2. ANGULARJS Frame Structure
ANGULARJS's design structure is similar to MVC, by declaring different struct classes, registering the corresponding code at different stages of the process event loop, to implement module loading, data processing, data binding to HTML rendering, and page display.
Cutting code in a framework structure, the aggregation of business code appears in a single structure class.

The main structure class has component, module and service three, with the current understanding, the execution of business code mainly depends on the entry of the project component (APP.COMPONENT.TS) Template refers to the HTML tag defined by the business component, which then refers to the business HTML template and the corresponding interaction logic to implement.
In contrast, the index.html file in the Angularjs project seems to have meaning only to refer to the main label of the project App-root, maybe there is a scene running multiple apps at the same time? Pending verification.

The structure classes in ANGULARJS have the following main types:

1) Component
Defines the page HTML template and the main page interaction logic, the direct performers of the data binding process.
The properties and methods defined in the component subclass can be referenced directly in the HTML template, implementing bidirectional binding of data and interactive events for HTML elements (onclick, mouseover, and other HTML element events that have corresponding directive in the ANGULARJS. )
Component subclasses need to be registered in the module to be referenced by the primary component.
Component is mainly responsible for the processing of data into a suitable format for presentation, or collection of page data into a format suitable for background logic processing, is not responsible for direct data access, this part of the work mainly by the service.

2) Service
The service is designed to perform data access processes, whether local or remote, where the service is shared by multiple component in a single-instance mode during work.
Classes defined as service need to be decorated by the @injectable () adorner, the internal principle is temporarily unknown, and the guesswork is the internal logic of the framework that is defined to implement service singleton sharing.

3) Module
There is only one ngmodule in a project, which defines a reference interface for business component, public service, and other third-party ANGULARJS plug-ins, which can be referenced in component only if the modules are declared in module.


Each part performs a reference to a different program
Imports primarily defines the Angularjs kernel and the various modules in the plug-in
Bootstrap defining the main component of the project (typically Appcomponent)
declarations define business component and also include Appcomponent
providers define a variety of common service

3. Use of ANGULAR-CLI
In Angular2, you can use ANGULAR-CLI to create projects and various components in a command-line manner

ng new {project_name} new project, automatic generation of directories and basic structure files
ng Server starts the project using the configuration in the preset configuration file
ng generate component {Component-name} creates a new component, generates a basic component declaration code, and registers the component with Ngmodule
ng generate service {service-name} [--module={component-name}] generates a new service, if--module is specified, The service will be registered to the specified ngmodule

4. Other
Angular1 and Angular2 's study notes, assorted recorded two documents, the real take out, the system can be organized only the only thing left.
Other HTML template syntax, directives and even typescript, is still smattering, even if writing code still need to be compared with the document, there is no systematic cognition, but also need to study deeply.

ANGULARJS Study Notes

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.