[Feature] Set the pre-selected values in the items array
See original GitHub issueIs your feature request related to a problem? Please describe. The API i’m consumming returns a list containing the select options (the label, the value & a boolean indicating if the option must be pre-selected or not). Something like :
options = [
{
label: 'label1',
value: 1,
selected: true
},
{
label: 'label2',
value: 2,
selected: false
},
{
label: 'label3',
value: 3,
selected: true
},
]
But currently I haven’t found an elegant solution to pre-select theses options.
Describe the solution you’d like
The possibility to pass a boolean (called selected or not) saying if the option must be pre-selected would be nice.
<ng-select [items]="(options)" [multiple]="true"></ng-select>
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Setting Array Default Values - NI - National Instruments
Complete the following steps to set the default value for an array element. Add an array shell to the front panel. Right-click an...
Read more >How to set default value for drop-down multiselect in angular 2 ...
The solution is to map the array items in order to obtain the values you want. For instance, this will preselect the fist...
Read more >How to Fill an Array with Defaults | by Cristian Salcescu
The fill() method changes all elements in an array to a default value. It begins from a start index (default 0 ) to...
Read more >Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >3 Ways to Set Default Value in JavaScript | SamanthaMing.com
Understanding the || Operator. Using Default Value as Function Parameter; Falsy Values · Compared to the && operator · What is the Elvis...
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
+1 for umangchadha’s comment above…
Angular is giving (the following) WARNING when we try to use ngModel inside a Reactive Form (formControlName).
_**It looks like you’re using ngModel on the same form field as formControlName. Support for using the ngModel input property and ngModelChange event with reactive form directives has been deprecated in Angular v6 and will be removed in a future version of Angular.
i am using formControlName instead of ngModel how can i preselect values in multiselect and single select?