0

In angular i want to check the component containing any input value is changed or Not.

Example.

i have a page with 5 controls (3 text box and 2 drop downs ) if the value got changed on textbox or drop down,i want to identify that is any value is changed or it is as previous.

please help me,if any one can..

pushp
  • 2,134
  • 4
  • 18
  • 31

2 Answers2

1

If you're using ReactiveForms you can use valueChanges like:

this.myFormGroup.valueChanges
 .debounceTime(500) // optional
 .subscribe(data => {
   // do some stuff with `data`
 });
Maxime Lafarie
  • 2,172
  • 1
  • 22
  • 41
  • Maxime,How to create myFormGroup .Can you tell me sample code. – pushp Apr 30 '18 at 12:22
  • @pushp I suggest you to follow this excellent [Todd Motto's Reactive Form tutorial](https://toddmotto.com/angular-2-forms-reactive), it will learn you the bases of Reactive Forms and its API. – Maxime Lafarie Apr 30 '18 at 12:25
  • if I have more than 100 controls and editable grids in the page at this situation do i have to explicit add these controls into myFormGroup . – pushp May 01 '18 at 06:55
  • No you're not forced to do that, you also can add them dynamically in a loop. – Maxime Lafarie May 01 '18 at 17:07
-1

In input field write (ngModelChange)="findchanges(inputValue)". Then in ts file get changes of that input field.