Home  >  Article  >  Web Front-end  >  In-depth understanding of Component components in Angular

In-depth understanding of Component components in Angular

青灯夜游
青灯夜游forward
2021-04-19 09:33:452161browse

This article will introduce to you the In-depth understanding of Component components in Angular component in Angular. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

In-depth understanding of Component components in Angular

Angular In-depth understanding of Component components in Angular


In-depth understanding of Component components in Angular is what makes up an Angular application Basic and Core. In layman's terms, components are used to package specific functions, and the orderly running of the application depends on the coordination between components. [Related tutorial recommendations: "angular tutorial"]

In-depth understanding of Component components in Angular essential elements

In-depth understanding of Component components in Angular

    ## @In-depth understanding of Component components in Angular (component metadata decorator)
@In-depth understanding of Component components in Angular The role of the decorator is to tell the Angular framework how to handle Typescript classes. It contains multiple properties, and the values ​​of these properties are called metadata. . Angular will render the component and execute the component's logic based on the metadata value.

    Template (template)
Template is used to define the appearance of a component. The template exists in the form of html and tells Angular how to render the component. We can use Angular's data binding syntax in the template to render data from the controller.

    Controller (controller)
The controller is an ordinary Typescript class, which will be decorated by the @In-depth understanding of Component components in Angular decorator. The controller contains All properties and methods of the component, and most of the page logic are written in the controller. The controller communicates with the template through data binding, the template displays the controller's data, and the controller handles events that occur on the template.

Example

import { In-depth understanding of Component components in Angular } from '@angular/core';

@In-depth understanding of Component components in Angular({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [AppService],
})
export class AppIn-depth understanding of Component components in Angular {
  title = 'app demo';

  .....
}

  • selector
##@In-depth understanding of Component components in Angular decorator specification CSS selector, which tells Angular to create and insert an instance of the component once the tag corresponding to this selector is found in the template HTML.

    templateUrl
templateUrl specifies an HTML file as the template for the component. You can also use the value of the template attribute to provide an inline HTML template

    styleUrls: ['./app.component.css']
styleUrls points to a set of CSS files in which styles to be used by components can be written.

    providers
An array of service providers required by the current component

    AppIn-depth understanding of Component components in Angular
The controller of the component, a Typescript class decorated by a decorator.

In-depth understanding of Component components in Angular Other elements

In-depth understanding of Component components in Angular元素For more programming-related knowledge, please visit:

Programming Teaching

! !

The above is the detailed content of In-depth understanding of Component components in Angular. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete