Posts

Showing posts with the label Angular

How to use @ContentChildren in Angular

Image
  Content Children ContentChildren is a parameter decorator that is used to get the QueryList of elements or directives from the content DOM. The QueryList is updated whenever the  child element/component is added or removed. The child element reference is set in  QueryList  just before the  ngAfterContentInit  lifecycle Hook method. Let's take one example to understand better about   Content Children   Step 1 : Create a project using command ng new  Content-children-Example Step 2:   Add 2 more component using  ng g c component-name Step 3:  Place the below code  in child.component.html <h1>This is child Page </h1> <h2>{{message}}</h2>   Step 4 : Place the below code in  child.component.ts   import { Component, OnInit } from '@angular/core';   @Component({    selector: 'app-child',    templateUrl: './child.component.html', styleUrls: ['./child.component.scss'] }) export class ChildComponent implements On