ng2-select icon indicating copy to clipboard operation
ng2-select copied to clipboard

Change the behavior on set items instead of on initialization

Open ronzeidman opened this issue 10 years ago • 3 comments

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)

ronzeidman avatar Jan 19 '16 10:01 ronzeidman

I was thinking to rewrite all this to observables so Items will be checked only after typing this will increase overall load spead

valorkin avatar Jan 19 '16 12:01 valorkin

Running into this issue as well, trying to use with async loaded data and is erroring out :/

bbrink68 avatar Jan 26 '16 16:01 bbrink68

This might help: https://github.com/valor-software/ng2-select/issues/635#issuecomment-281094377

JimJafar avatar Feb 20 '17 17:02 JimJafar