I have my code in HTML like this.
<div class="col-md-10">
<ng-select [items]="tests" (data)="updateSelected($event, 'test')">
</ng-select>
</div>
My typescript code is as follows
@Input() tests: Option[] = []; I have tests coming as input from previous component
@ViewChildren(SelectComponent)
private selectComponents: QueryList<SelectComponent>;
ngAfterViewInit() {
this.selectComponents;
}
How do I set some value as default value here in selectComponents or is there any other way to set some value as default value using ng-select.
Use ng-init to set default value for ng-options . Save this answer.
The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute. The option that is having the 'selected' attribute will be displayed by default on the dropdown list.
Use ngModel binding as below.
<ng-select options="users" [(ngModel)]="selectedValue">
</select>
ngOnInit() {
this.selectedValue = ["1"]
}
Array item value is option id. https://basvandenberg.github.io/ng-select may be helpful for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With