I'm trying to integrate Select2
into the Angular2
app I'm building. I managed to get select2
running and my multiple selects are transformed as expected. My problem now is how am I supposed to get the selected values and which event should I use for the binding. I tried binding (change)
event on the select element but nothing happened. Maybe I should use some other event on the created by the plugin select2-container
element?
The select2
plugin is integrated following this answer.
Anybody tried similar mix? Is it possible to get it work or I have to switch to ng2-select directive instead?
Update
Bonus question :) - Even if I give up select2
and use standard multiple select, how should I get its value? I tried binding it to a property with [(ngModel)]="_selectedValues"
but it remains empty when I select any option. Is the multiple checkbox the only way for multiple choice?
Update 2
For the bonus question - the workaround I found was to use one way event binding like (change)="selectedValues=$event.target.selectedOptions"
. Then I added a setter
for the selectedValues
property like this:
public set selectedValues(value: Array<any>) {
this._selectedValues.length = 0;
for(let v of value){
this._selectedValues.push(v.value);
}
};