2021-09-10

Angular 8 ng-select value object

 





Because you set the binding to ID: bindValue="ID". Remove it and it should work.

Read more about bindings here: https://ng-select.github.io/ng-select#/bindings








Source URL: https://stackblitz.com/run?file=src%2Fbindings-default-example.component.ts




html

<ng-select [items]="defaultBindingsList"
           [(ngModel)]="selectedCity">
</ng-select>



ts
import { ComponentOnInit } from '@angular/core';

@Component({
    selector: 'bindings-default-example',
    templateUrl: './bindings-default-example.component.html',
    styleUrls: ['./bindings-default-example.component.scss']
})
export class BindingsDefaultExampleComponent implements OnInit {

    defaultBindingsList = [
        { value: 1label: 'Vilnius' },
        { value: 2label: 'Kaunas' },
        { value: 3label: 'Pavilnys'disabled: true }
    ];

    selectedCity = null;

    ngOnInit() {
        this.selectedCity = this.defaultBindingsList[0];
    }
}









No comments:

Post a Comment