Angular Dropdown Change() vs valueChanges.subscribe

1.4k Views Asked by At

I have an Angular form built using Reactive Forms. The form contains 3 select elements. I want to add the value change detection to one dropdown and other two will change accordingly to the values of the first dropdown. Between Change() and valueChanges.subscribe, which will be the best to use and what is the difference.

2

There are 2 best solutions below

0
JoH On

They are fundamentally the same thing, each time the value of your dropdown changes, a function that change the value of the two other dropdowns is executed.
valueChanges is an Observable, you have to unsubscribe from it at some point, for instance when the component is destroyed.

1
Fateh Mohamed On

it depends on your use case

  1. if your list contain an autocomplete or a realtime search to fill options i recommand the use valueChanges that returns an observable.
  2. if it's a simple dropdown list use change event instead it's simple and no need to use valueChange and handle unsubscribes