valor-software / ng2-select

Angular based replacement for select boxes
http://valor-software.github.io/ng2-select/
MIT License
676 stars 588 forks source link

SelectItem with id=0 #894

Open nerbos opened 6 years ago

nerbos commented 6 years ago

Hi,

When you create a SelectItem with an id=0 the object will be created with the text as id, due to:

ng2-select/src/select/select-item.ts (line: 11)

    if (typeof source === 'object') {
      this.id = source.id || source.text;`

I would suggest to change this code into something like this:

    if (typeof source === 'object') {
      this.id = (typeof source.id === 'undefined' || source.id === null ? source.text : source.id);`

Best regards

nulayuhz commented 5 years ago

No wonder why my option with id = 0 is not showing up! This is a really big bug.

nikhilkhot46 commented 5 years ago

No wonder why my option with id = 0 is not showing up! This is a really big bug.

this.items = [{ id: "0", text: "Inactive" }, { id: "1", text: "Active" }];

like this, we can implement Capture