Unable to select an item.
However when "suggest" is enabled, you can begin typing an item and tab out and this works.
Clicking an item should select the value.
Browser:
System:
@VishalMadhvani Thank you for the provided example.
The selection is not working in your scenario for the following reasons:
ngFor directive by iterating over the provided data items. The ngFor internally uses IterableDiffers to detect changes in the data array. IterableDiffers compares the objects by reference and not by structure and property value. So every time the getData function in your code is called, for the ngFor directive it looks like all of the items are new and it recreates the mark-up.click event listener which triggers selection on item click is attached to the items generated by the ngFor.getData func to execute, as it is run on every change detection cycle, which changes the data and forces the ngFor to clear the old mark-up, unsubscribe from the click event, and then create the new mark-up and bind to the click event anew. After unsubscribing, the click event handler is not called for the current click occurrence, even though it is initially queued for execution.I don't really think that's an issue with the component as it's not designed to work with data that's changing on every change detection cycle. The latter would be hugely impractical - it would cause bad performance especially when the ComboBox options list is populated with larger data sets or is used in a slower browser. And normally it's not even necessary. The user of the component sets or changes the data generally in one of those situations:
What is actually your motive for using it in the way you describe and what are you trying to achieve?
I've modified your example as you can see here, to parse (map) the data only on component init. Won't that work for you?
@dimitar-pechev thanks for the detailed explanation of why it wasn't working. I can't remember why I was trying to do it that way but I wouldn't be surprised if I ended up doing what you have suggested.
Most helpful comment
@VishalMadhvani Thank you for the provided example.
The selection is not working in your scenario for the following reasons:
ngFordirective by iterating over the provided data items. ThengForinternally usesIterableDiffersto detect changes in the data array.IterableDifferscompares the objects by reference and not by structure and property value. So every time thegetDatafunction in your code is called, for thengFordirective it looks like all of the items are new and it recreates the mark-up.clickevent listener which triggers selection on item click is attached to the items generated by thengFor.getDatafunc to execute, as it is run on every change detection cycle, which changes the data and forces thengForto clear the old mark-up, unsubscribe from the click event, and then create the new mark-up and bind to the click event anew. After unsubscribing, the click event handler is not called for the currentclickoccurrence, even though it is initially queued for execution.I don't really think that's an issue with the component as it's not designed to work with data that's changing on every change detection cycle. The latter would be hugely impractical - it would cause bad performance especially when the ComboBox options list is populated with larger data sets or is used in a slower browser. And normally it's not even necessary. The user of the component sets or changes the data generally in one of those situations:
What is actually your motive for using it in the way you describe and what are you trying to achieve?
I've modified your example as you can see here, to parse (map) the data only on component init. Won't that work for you?