Detect changes in parent component using @Input and ngModelChange in Angular

Here we are going to see how the data will be communicated from parent component to child component using @Input() method.

@input() can be used in two ways.
·        Two way binding with @Input()
·        One way binding using ngOnChange() event and @input()

Here we gonna look at one way binding with ngModelChange with @Input().

Technical implementation:
            Here we have two component AppComponent (parent component) ChildComponent ( child component).

App component contains Textbox, When user enters any of the data, it will be passed to Child component and display as a span there.


import { Component } from '@angular/core';
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent {
 public inputValue : string;
  onChange(UpdatedValue : string) :void
    this.inputValue = UpdatedValue;


<div style="border: 1px solid chocolate; height: 250px;

width: 350px; padding: 10px 10px" > 
 <span> <b>Parent component</b></span>
  Type here : <input type="text" [ngModel]='inputValue'
   (ngModelChange)='onChange($event)' />
  <child-component [message]='inputValue'></child-component>


import { Component, OnInit, Input } from '@angular/core';

  selector: 'child-component',
  templateUrl: './child-component.component.html',
  styleUrls: ['./child-component.component.css']
export class ChildComponentComponent {
  @Input() message:string;
  constructor() { }


<div style="border:1px solid chocolate; width:300px;

   height: 120px; padding: 10px 10px">
   <b> Child component</b><br><br>
    you entered {{message}}

Add FormsModule in the app.module.ts

That's It !!