To set the default value in the Combo box assign the value in js code directly.
Ex:
HTML Code
JS Code
Output
Ex:
HTML Code
<template>
<lightning-combobox
name="progress"
label="Status"
value={value}
placeholder="Select Progress"
options={options}
onchange={handleChange} ></lightning-combobox>
<p>Selected value is: {value}</p>
</template>
JS Code
import { LightningElement, track } from 'lwc';
export default class ComboboxBasic extends LightningElement {
value = 'inProgress';
get options() {
return [
{ label: 'New', value: 'new' },
{ label: 'In Progress', value: 'inProgress' },
{ label: 'Finished', value: 'finished' },
];
}
handleChange(event) {
this.value = event.detail.value;
}
}
Output
very good post
ReplyDeletein my case the value is still empty
ReplyDeleteThanks a lot for this Solution...
ReplyDeletey love you! <3
ReplyDeleteFor me still default value "Select an option is showing up"
ReplyDelete