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.

[Feature] Set the pre-selected values in the items array

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
contactiprajucommented, Mar 5, 2021

+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.

For more information on this, see our API docs here:
https://angular.io/api/forms/FormControlName#use-with-ngmodel**_
0reactions
umangchadhacommented, Dec 16, 2020

i am using formControlName instead of ngModel how can i preselect values in multiselect and single select?

Read more comments on GitHub >

github_iconTop 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 >

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