question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add new items to list of in dropdown

See original GitHub issue

I have 6 ng-selects that are being dynamically built based on a list. I’m trying to give the user the option of adding a value to a drop-down if the value they want doesn’t exist. I have created an interfacte that adds the item to the values list of that dropdown behind the scenes. After the add, the new option isn’t display in the drop-down, but it does exist within the object that built the list.

Is there a fresh I can call or something?

Here is the ng-select and the add function.

<div class="padding-bottom col-xs-12 col-md-4" *ngFor="let option of segmentOptions"><div *ngIf="option.txt_Header_Name !== 'UPC'">
              <label>{{option.txt_Header_Name}}</label>
              <ng-select id="header-{{option.id_Header_ID}}" [items]="option.values" bindLabel="txt_Header_Value" [loading]="optionsLoading"></ng-select>
            </div>
          </div>
addHeaderValue(header, headerValue) {
    for (let i = 0; i < this.segmentOptions.length; i++) {
      if(this.segmentOptions[i].txt_Header_Name === header.txt_Header_Name){
        this.segmentOptions[i].values.push({id_Header_Value_ID: "00000", id_Header_ID: 3, txt_Header_Value: headerValue});
        break;
      }
    }
  }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
abney317commented, Nov 30, 2018

If anyone runs across this and is confused as to why the change detection example is putting an array back into another array which causes your items to not be there, this is what I did instead:

this.items.push({id: 1, name: 'New item'}); this.items = this.items.slice(0);

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Add New Items Sorted Excel Drop Down List - Macro
Set Up the Data Entry Sheet · Select the cells where you want the Client drop down lists · On the Ribbon, click...
Read more >
How to automatically add new items to a drop down list
Go to tab "Insert" on the ribbon. · Select cell A2 · Create a new named range by pressing CTRL + F3 or...
Read more >
How to Add Item to Drop-Down List in Excel (5 Methods)
5 Methods to Add Item to Drop-Down List in Excel · Choose List from the Allow field. · Select Shift cells down from...
Read more >
How to add an item to a drop down list in ASP.NET?
3 Answers 3 ; 60 · DropDownList1.Items.Insert(0, new ListItem("Add New", "")); · answered Jul 4, 2013 at 11:24 ; 38 · ListItem lst...
Read more >
Add New Items to Excel Drop Down List - Contextures Blog
When the code detects a new item, it asks if you want to add it to the drop down. If you click Yes,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found