ng-select
ng-select copied to clipboard
cannot set the default value
In my case, I am binding to a property of an object. The default value cannot be set.
<ng-select
name="eventDataCode"
id="eventDataCode"
[options]="codeList"
placeholder=""
[(ngModel)]="eventData.event.code" required ></ng-select>
ngOnInit() {
this.eventData = new EventData;
this.eventData.event.code = "abc";
console.log(this.eventData.event);// code:undefined
console.log(this.eventData.event.code);// code:abc
}
Hi @jusfeel I have the same issue, did you by any chance managed to resolve it? Thanks.
(this is wrong, please forget). Yes. Just make the this.eventData.event.code javascript 'object'. "string" won't work.
Apologies. Forget above. Make options in a option list by implement a shape like this:
export class Code {
label: string;
value: string;
}
It should work.