-1

I have a modal showing a form with with ng-select that should use for both adding new element to a list, but also to edit existing elements. The selected items are pushed to an array in the element

In adding, everything works well, but in edit I do not see the element`s selected items.

Don't know if relevant, but when adding, I'm using @ViewChild(NgSelectComponent).clearModel() to show an empty form (I know it's not the syntax, it's just for the post.).

How can I programmatically select items in ng-select inside a modal? All I saw was to change the list and none mentioned a modal.

Thanks.

PeteGO
  • 5,597
  • 3
  • 39
  • 70
Liran_T
  • 69
  • 7
  • The ng-select can be bound to a model with 2-way binding. In your controller you can simply change the model value and it will update in the UI automatically. Is this what you're asking? – PeteGO Aug 27 '23 at 11:46
  • Yes, but more of the specific field needed. I tried elm.selected = true and it didn't work. Couldn't found what will. – Liran_T Aug 27 '23 at 13:06
  • If 2-way binding isn't helping, you could host the information in a service and just have everything reference it there. That way anything done to the items on any page or modal is instantly propagated everywhere else because the single source of truth has changed. – Myles Morrone Aug 27 '23 at 16:15

0 Answers0