Add new items to list of in dropdown
See original GitHub issueI 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:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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);
https://github.com/ng-select/ng-select#change-detection