Autocomplete formcontrol valueChanges should not be fired when user select option
Autocomplete formcontrol valueChanges fired when user select option
Please, look at this (open console): https://stackblitz.com/edit/angular-8zucqs?file=app/autocomplete-display-example.ts
Angular - 7.2.0, Material - 7.2.1
Bros, i need this functionality.
I'm not sure I get what the issue is. When is it supposed to fire valueChange event, aside from when the value has changed?
If you look at an example to autocomplete component, you will see something like this:
constructor() {
this.filteredStates = this.stateCtrl.valueChanges
.pipe(
startWith(''),
map(state => state ? this._filterStates(state) : this.states.slice())
);
}
I'm as a regular developer, think that is a place where I can make a call to API. So I place code into map pipe. If I type something in input, that call will be fired (it is OK), but when I select an option, that call will be fired again (valueChanges). So if it isn't an issue, please, give me example how to avoid it.
If you look at an example to autocomplete component, you will see something like this:
constructor() { this.filteredStates = this.stateCtrl.valueChanges .pipe( startWith(''), map(state => state ? this._filterStates(state) : this.states.slice()) ); }I'm as a regular developer, think that is a place where I can make a call to API. So I place code into
mappipe. If I type something in input, that call will be fired (it is OK), but when I select an option, that call will be fired again (valueChanges). So if it isn't an issue, please, give me example how to avoid it.
When you select option, valueChanges fired with [Object], try filter
constructor() {
this.filteredStates = this.stateCtrl.valueChanges
.pipe(
startWith(''),
filter(x => typeof x === 'string'),
map(state => state ? this._filterStates(state) : this.states.slice())
);
}
Closing since this works as expected.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
If you look at an example to autocomplete component, you will see something like this:
I'm as a regular developer, think that is a place where I can make a call to API. So I place code into
mappipe. If I type something in input, that call will be fired (it is OK), but when I select an option, that call will be fired again (valueChanges). So if it isn't an issue, please, give me example how to avoid it.