md-on-select on md-chips gets called twice due to keyboard selection
I have a md-chips with an internal md-autocomplete used to search for chips asynchronously from server. I also have a method calls associated with md-on-select. In the sample given below inside the
<md-chips ng-model="ctrl.selectedChips" md-autocomplete-snap
md-transform-chip="ctrl.transformChip($chip)"
md-on-select="selectChip($chip)"
md-on-add="addChip($chip)"
md-on-remove="removeChip($chip)"
md-require-match="true">
<md-autocomplete
md-selected-item="ctrl.selectedItem"
md-search-text="ctrl.searchText"
md-items="item in ctrl.chipSearch(ctrl.searchText)"
md-item-text="item.text"
placeholder="+ text">
<span md-highlight-text="ctrl.searchText">{{item.text}}</span>
</md-autocomplete>
<md-chip-template>
<span>{{$chip.text}}</span>
</md-chip-template>
</md-chips>
content of selectChip
selectChip() {
console.log('selected');
}
Everytime I use keyboard (arrow or backspace) to perform selection the selectChip() gets called twice. Whereas if I click on a chip using mouse the same method only gets called once. I have some logic that should only be run once each time the user selects a chip. This seems like a bug. However if I have made a mistake in my configuration, happy to change. Please suggest.
You are right. If I click the chip the method only get called once but using key-board keys including delete the method gets call twice. +1
@vshanbha Can you please convert your code above into an actual Codepen so that we can debug it a bit and find the root cause? Thanks!
@topherfangio Here is a minimal code that recreates that issue. http://codepen.io/vshanbha/pen/zqNZbq
@vshanbha Perfect; thanks!
This issue is closed as part of our ‘Surge Focus on Material 2' efforts. For details, see our forum posting @ http://bit.ly/1UhZyWs.