The behavior is set on initialization, but sometimes the items are not available on initialization and they are only received a bit afterwords causing errors since the behavior is governed by the first item.
instead you can move the logic to the items setter
@Input() set items(value:Array<any>) {
this._items = value;
this.itemObjects = this._items.map((item:any) => new SelectItem(item));
this.behavior = this.itemObjects.length > 0 && this.itemObjects[0].hasChildren() ?
new ChildrenBehavior(this) : new GenericBehavior(this);
}
(maybe you could somehow check if the previous behavior is like the new one for not creating a new behavior all the time, or just create both lazily and store them, then switch between the two if the items change)
I was thinking to rewrite all this to observables
so Items will be checked only after typing
this will increase overall load spead
Running into this issue as well, trying to use with async loaded data and is erroring out :/
This might help: https://github.com/valor-software/ng2-select/issues/635#issuecomment-281094377
Most helpful comment
Running into this issue as well, trying to use with async loaded data and is erroring out :/