Liverpoolfc.tv: presents. IO/guide/archi…

Before a view is displayed, Angular evaluates the directives and resolves the binding syntax in the template to modify the HTML elements and the DOM, according to your program data and logic. Angular supports two-way data binding, meaning that changes in the DOM, such as user choices, are also reflected in your program data.

Before a view is displayed, Angular evaluates Angular directives in the page template, parses binding information, and modifies HTML elements and the DOM. Angular supports bidirectional binding, which means that changes to the DOM, such as user selection, are automatically reflected in the application’s data.

With services

A service class definition is immediately preceded by the @Injectable() decorator. The decorator provides the metadata that allows other providers to be injected as dependencies into your class.

Angular Services are defined through the @Injectable() decorator, which provides metadata for dependency injection by other providers.

Module

Defined by the decorator @ngModule (). An example:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [].bootstrap: [AppComponent]
})
Copy the code

Contains the following sections:

  • declarations: The components, directives, and pipes that belong to this NgModule.
  • imports: Other modules whose exported classes are needed by component templates declared in this NgModule.
  • exports: The subset of declarations that should be visible and usable in the component templates of other NgModules.

A root NgModule has no reason to export anything because other modules don’t need to import the root NgModule.

The components that belong to an NgModule share a compilation context.

The relationship between an NgModule and Component is 1: N, one-to-many.

In JavaScript each file is a module and all objects defined in the file belong to that module. The module declares some objects to be public by marking them with the export key word. Other JavaScript modules use import statements to access public objects from other modules.

Each JavaScript file is a module, and all objects defined in that file belong to that Module. Module uses the export keyword to declare a portion of the object to be public. JavaScript Modules use imports to import public objects from other modules.

Angular libraries

Declare Angular libraries with the @angular prefix.

For example, import Angular’s Component decorator from the @Angular /core library like this.

Import {Component} from ‘@angular/core’;

Component

Here’s an example:

  • selector: A CSS selector that tells Angular to create and insert an instance of this component wherever it finds the corresponding Tag in template HTML. For example, if an app’s HTML contains, then Angular inserts an instance of the HeroListComponent view between those tags.

A bit like the place holder defined in SAP UI5’s index.html

  • templateUrl: The module-relative address of this component’s HTML template. Alternatively, you can provide The HTML template inline, This template defines the component’s host view.

Data binding syntax in Angular templates

Remember this picture:

Here’s an example:

  • {{hero.name}}: Displays Component’s hero.name property in the li tag.
  • [hero]: The [hero] property binding passes the value of selectedHero from the parent HeroListComponent to the hero property of the child HeroDetailComponent.

Pass the selectedHero value from HeroListComponent to the Hero property of the HeroDetailComponent.

  • (click): The (click) event binding calls The component’s selectHero method when The user clicks a hero’s name. When the user clicks on the hero name, the Component selectHero method is called.

Syntax for bidirectional binding: <input [(ngModel)]= “hero.name” >

Two-way data binding (used mainly in template-driven forms) combines property and event binding in a single notation.

In two-way binding, a data property value flows to the input box from the component as with property binding. The user’s changes also flow back to the component, resetting the property to the latest value, as with event binding.

Angular Directive

Angular templates are dynamic. When Angular renders them, it transforms the DOM according to the instructions given by directives. A directive is a class with a @Directive() decorator.

Angular Template is dynamic, and when the template is rendered, the DOM is converted based on the directives contained in the template. An Angular directive is a class decorated with @ directive ().

Structual directive

Structural directives alter layout by adding, removing, and replacing elements in the DOM.

Structure Directive affects interface layout by adding, deleting, and replacing elements in the DOM.

attribute directive

Attribute directives alter the appearance or behavior of an existing element. In templates they look like regular HTML attributes, hence the name.

Affects the appearance or behavior of an existing element that looks like a normal HTML attribute in an Angular template, hence the name.

An example of Attribute directive: The ngModel directive, which implements two-way data binding, is an example of an attribute directive. ngModel modifies the behavior of an existing element (typically ) by setting its display value property and responding to change events.

< input [(ngModel)] = “hero. The name” >

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: