Hey, i am using ng2-select and i am quiet satisfied.
I spent the last 3 hours to set the initial data of the select.
My first attempt was to use "active:
code:
<ng-select [active]="active"...
public active = ['Amsterdam'];
Compiler:
Can't bind to 'active' since it isn't a known property of 'ng-select'
After that I tried around with some hacks but so far I couldnt find a solution.
I also want to use it as a multi select, but i am already failing on the single selection.
Unfortunately there is no demo and i am out of ideas..
Another little thought:
CSS height is not working correctly.
I have to set the height initially but if it changes (like on multiselect), therefore the hight stays the same..
Thank you for this very helpful component!
Greetings
Emanuel
Dupe of #379? I too have been trying to get [active] to work. On #379, he says to use [initData]
nope tried that, too.
Same didnt work
I had this problem, it was actually giving me errors for using "data" to populate the initial selected values in rc5, because there is an event called "data" which causes a conflict.
So reading the source I did bump into [initData] and it worked.
I think maybe I maybe had some conflicts with the RC versions. With initData it's fine after setup changes.
The readme on github is not updated yet.
I'm having the same issue here. It looks like the right attribute should be [active] right now in stead of [initData], but I keep getting this error:
selectedItems.map is not a function
have the same problem here:
[active]="value[0]" then
selectedItems.map is not a function
[active]="value[0]" must be the array
@karmis Do you have a working example?
same here.. selectedItems.map is not a function
I have found the solution, you need to set the active attribute like this:
[active]="[arrayWithObjects[objectIndex]]"
In most cases this means you should refactor your data object to this format to get It working.
Thanks! In my case it was just [active]="[object]", because it was a single object!
anybody had success with an array of objects as active property? how to do this?
import { SelectComponent } from '../node_modules/ng2-select/';
export class SelectButtonComponent {
@ViewChild(SelectComponent) select: SelectComponent;
public method(e:any):void {
this.select.active = [value.toString()];
}
}
I used the way that directly change its active value in 'SelectComponent', hope it works for you.
I found this when trying to solve in reactive forms. Need to setValue like this:
this.select.active = [item.category];
this.form.setValue({
name:this.item.name,
description:this.item.description,
category:[this.item.category.name],
});
this is assuming that you are using objects and not strings as items.
thanks @XidongHuang
just using [active]="myInitialStringArray" worked for me
[items] already contains all items to be displayed .. I just want to select one of those to be selected initially .. how to do that? why i should give the data again via active ?
Most helpful comment
I have found the solution, you need to set the active attribute like this:
[active]="[arrayWithObjects[objectIndex]]"
In most cases this means you should refactor your data object to this format to get It working.