import { Injectable } from '@angular/core';
import { HEROES } from './mock-heroes';
@Injectable({
// declares that this service should be created
// by the root application injector.
providedIn: 'root',
})
export class HeroService {
getHeroes() { return HEROES; }
}
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.
Parent calls an @()as a reference of child
Pipes are simple functions to use in to accept an input value and return a transformed value.