Reputation: 2417
I am having Filter autocomplete
i,e (Vehicle Type) and Select with multiple selection
i,e (Vehicle model) components on the same page as shown in below image:
Here i want to performing 2-way data binding with Select with multiple selection
component.
If i select Vehicle Type
as Cars , then the cars Vehicle Model
as to come like this:
If i select Vehicle Type
as Bikes , then the bikes Vehicle Model
as to come like this:
Here is the stackblitz link.
Upvotes: 0
Views: 242
Reputation: 27343
FormControl have a valueChages method that returns an observable that emits the latest value.
Try this
ngOnInit() {
this.list = this.CarList;
this.filteredOptions = this.myControl.valueChanges
.pipe(
startWith(''),
map(value => this._filter(value))
);
this.myControl.valueChanges.subscribe((d) => {
if (d === 'Cars') {
this.list = this.CarList;
} else {
this.list = this.BikeList;
}
})
Example:https://stackblitz.com/edit/angular-4kxeab-glx4vg
Upvotes: 1