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.

Default selection / Programmatically changing selection

See original GitHub issue

I have tried all possible ways to set the default value of select box (single). none worked.

I have tried:-

[active]="{id:'1' , text : 'foo' }"
[active]="[{id:'1' , text : 'foo' }]"

[data]="{id:'1' , text : 'foo' }"
[data]="[{id:'1' , text : 'foo' }]"

Is there a way to change selection Programmatically ?

angular 2.0.0-rc.4 ng2-select 1.0.3

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:4
  • Comments:15

github_iconTop GitHub Comments

5reactions
littleStudentcommented, Sep 12, 2016

you can do something like this. Its not a clean solution but it works.

@ViewChild(SelectComponent) select: SelectComponent;

changeSelection() {
     if (this.select) {
          this.select.initData = [{id: 1, text: 'new value'}];
          this.select.ngOnInit();
     }
}
2reactions
megasharkscommented, May 14, 2017

My 5 cents. It was tough! template <ng-select name=“dealers” [active]=“activeDealer” [multiple]=“false” [items]=“dealers”
(data)=“refreshValue($event)”//schould be present in code placeholder=“dealers” > </ng-select>

// delcarations dealers : Array < any > = [] activeDealer:Array <any>=[];

// somewhere in code .(async operation) The funny part is with _temp var.
// receiving AJAX response as responseData let _temp = []; responseData.result .forEach((item, index) => { _temp .push({id: item.id, text: item.title}) }); this.dealers = _temp; this.activeDealer=[this.dealers[1]]

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to programmatically change the selected option in an ...
I need to change the selection that is actually displayed in the select box so I can reset it to "show all" so...
Read more >
How can I programmatically set a default select option in for ...
I have a for loop in my code that creates elements in a table using data from the database. Each row has a...
Read more >
Programmatically Preselect Dropdown Using Javascript
This page describes how to set the selected item on an HTML dropdown list after the page has been rendered using javascript.
Read more >
How do you programmatically deselect an item after a ... - Telerik
In short, the article shows how you can clear the selection of input by changing its Value parameter to the default value for...
Read more >
Row Selection - JavaScript Data Grid
suppressRowClickSelection : If true , rows won't be selected when clicked. Use, for example, when you want checkbox selection or your managing selection...
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