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.

Selecting a value bind the same value to all ng-select dropdowns

See original GitHub issue

Hi I am using ng-select in ngFor, thus showing up the more than one ng-select dropdown in UI. But issue is whenever i am trying to select a value for a dropDown, it auto selects the same value for all other dropdowns.

Template:

<div>
  <ul class="attrib-list" *ngFor="let car of allCarsModelsInState">
    <li>{{car.description}}</li>
    <div class="pos">
      <ng-select [items]="values" [multiple]="true" [closeOnSelect]="true" placeholder="{{'select' | translate}}" [searchable]="false"
        [(ngModel)]="selectedCars" (focus)="getListOfCars(car)" [clearable]="false">
        <ng-template ng-multi-label-tmp>
          <span>{{selectedCars}}</span>
        </ng-template>
      </ng-select>
    </div>
  </ul>
</div>

ts file: values = [‘c1’,‘c2’,‘c3’…] Values for cars will be prepared dynamically whenever i click on a dropdown.

export class Cars{
selectedCars[] = [];

getListOfCars(car){
this.values = carvalues
}
}

Please help Thanks

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
varnastadeuscommented, Aug 9, 2018

use stackoverflow for this type of questions

0reactions
Exlordcommented, Sep 18, 2018

you need to use array indexes or object keys for ngModel.

<div *ngFor="let row of selectedFields;index as i">
    <div class="form-group m-form__group row">
        <label class="col-form-label col-sm-12">Field</label>
        <div class="col-lg-6 col-md-9 col-sm-12">
            <ng-select [items]="fieldsByBusiness"
                       bindLabel="name"
                       bindValue="id"
                       [(ngModel)]="selectedFields[i]"
                       [ngModelOptions]="{standalone: true}"
                       (change)="onFieldsByBusinessChange($event)"
            >
            </ng-select>
        </div>
    </div>
</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

ng select - multiple values - select same values more than ...
This way you will end up with an array of values that are unique, but the user is tricked into believing he is...
Read more >
AngularJS: API: select
When an item in the <select> menu is selected, the value of the selected option will be bound to the model identified by...
Read more >
Angular ng-select
A function to compare the option values with the selected values. The first argument is a value from an option. The second is...
Read more >
ng-select How to programmatically set a value
Connect with:​​ this. optionsSelect = [ { value: '1', label: 'Option 1' }, { value: '2', label: 'Option 2', SELECTED: true }, {...
Read more >
Angular Basics: How To Get Value of Selected Dropdown ...
Using ngModel; Using viewChild. Our example app has three components with the same HTML markup, a dropdown with a list of NBA teams,...
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