Angular

Component

  • Component basically consists of logic, template (UI) and style

import { Component } from '@angular/core';

@Component({
  selector: 'app-component-overview',
  templateUrl: './component-overview.component.html',
  styleUrls: ['./component-overview.component.css']
})
export class ComponentOverviewComponent {
  
}

Life Cycle

  • ngOnChange (Trigger when state is changed) -> ngOnInit -> ngDoCheck -> ngAfterContentInit -> ngAfterContentChecked -> ngAfterViewInit -> ngAfterViewChecked -> ngOnDestroy

View Encapsulation

Get Props from parent

Child emit event to the parent

Parent calls an @ViewChildarrow-up-right()as a reference of child

Content Projection

Pipe

  • Pipes are simple functions to use in template expressionsarrow-up-right to accept an input value and return a transformed value.

  • The built-in pipes include date, upper case, lower case, etc

Directive

Dependency Injection

  • Inject by constructor on component

Re rendering

  • Angular uses a different approach called "change detection, with help of zonejs Angular tracks changes in the component's state and bindings by comparing the current and previous values of the bindings. When changes are detected, Angular updates the corresponding parts of the actual DOM by using renderer 2

  • Angular walks your components from top to bottom, looking for changes. Angular runs its change detection mechanism periodically so that changes to the data model are reflected in an application’s view

  • Change Detection Initiation: Angular triggers the change detection process, either explicitly or automatically based on certain events (such as user interactions or asynchronous operations).

  • Component Tree Traversal: Angular traverses the component tree, starting from the root component, and checks each component for changes. This traversal can be considered a top-down approach.

  • Change Detection and Update: For each component, Angular compares the current state and bindings with their previous values to detect changes. If changes are detected, Angular updates the component's views and the associated DOM elements.

  • DOM Update: After detecting changes and updating the component's views, Angular applies the necessary changes to the DOM to reflect the updated state.

Last updated

Was this helpful?