0

I am relatively new to angular. I am currently working on my first project and got to know ng-select. Great modification but now I have a problem:

I have an array of objects as options from which are a few pre-selected. These objects all differ in at least one aspect which is the ID. The description can be the same but this should be rare. When two of the pre-selected Objects have the same name then only one is selected. This only happens when bindLabel = "name" when bindLabel = "id" then both are selected and shown.

How can I fix this? Is there an option to bindLabel ="id" but show the "nam" or something like this? Thanks for the help. Images are below.

Code of ng-select

Picture of select with id

Picture of select with name

Model of Object

aynber
  • 22,380
  • 8
  • 50
  • 63
Rood
  • 1
  • 2
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 27 '21 at 07:06
  • For everyone checking on this question. I couldn't exactly fix the problem. However I created an extra attribute in my model that combines all the shown attributes. This reduces the chance that two objects have the exact same value and are not correctly shown. – Rood Apr 05 '22 at 14:30

1 Answers1

0

There is also a bindValue property which decides which part of the object is to be selected as value(on select).

You can read more about it here

If I understand correctly, You are trying to achieve bindLabel= "id + name"

There are a few solutions to your problem here.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 28 '22 at 16:17