ng-select icon indicating copy to clipboard operation
ng-select copied to clipboard

cannot set the default value

Open jusfeel opened this issue 7 years ago • 2 comments

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
}

jusfeel avatar Sep 26 '17 10:09 jusfeel

Hi @jusfeel I have the same issue, did you by any chance managed to resolve it? Thanks.

kajdzo avatar Nov 14 '17 14:11 kajdzo

(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.

jusfeel avatar Nov 14 '17 15:11 jusfeel