Hi I am new to angular. I tried to use ngx-select to do the search for dropdown. i set the defaultValue as {'id':'1', 'text': 'project 1'}. But the field shows the placeholder text instead of default value. Please advise how can I display the default value in the input dropdown field. thanks
projectIdList=[{'id':'1', 'text': 'project 1'}, 'id':'2', 'text': 'project 2'}, 'id':'3', 'text': 'project 3'}];
[defaultValue]="defaultProjectIds"
(selectionChanges)="projectIdSelectionChange($event)"
[multiple]="false" autoClearSearch="true"
[allowClear]="true">
ngx-select version: 3.5.9
wrong repo dude.
I use two way building like:
html:
class = "category-items"
name = "category"
bindLabel = "title"
bindValue = "id"
[(ngModel)] = "categoryDefaultValue"
dropdownPosition = "top"
(change)="slectCategory2($event)">
tc:
public categoryDefaultValue = 1; //set the default value(id)
Hi @joelau71 ... I tried the same thing. My problem is, when I click on close icon ('x') the change event is triggered. There I check if the ng-model is null or empty. If found empty then I set a default value which is not getting set. Can you help me?
I solved my problem by using the (clear) event. What I did:-
<ng-select name="data" [items]="mappedData"
data-[(ngModel)]="code" bindLabel="name"
bindValue="code" placeholder="Select Code"
(clear)="resetCode()" data-(change)="codeChanged( code )"
notFoundText="Code Not Found">
And in TS, I added the method:-
resetCode() {
M.toast( { html: 'Setting by default the first Code', classes: 'red rounded' } );
this.code = this.mappedData[0].code;
this.codeChanged( this.code );
}
This worked perfectly as expected.
Most helpful comment
wrong repo dude.