You need to sign in to do that
Don't have an account?

LWC: Cannot remove undefined as a value
I have a lwc which displays few account fields. I am using wire service to display account field values. But when there is no value, it shows undefined as a value in LWC. I want to show it as a blank.
I tried several ways but couldn't come up with a solution. Please help.
Here is the javascript code:
export default class AccountTab extends LightningElement {
@api recordId;
@api accountList;
@wire(getAccounts, {recordId:'$recordId'})
wiredAccounts({data,error}){
if(data){
this.accountList = data;
console.log('current record id : '+this.recordId);
this.error=undefined;
}else if(error){
this.error=error;
this.accountList=undefined;
}
}
}
I tried several ways but couldn't come up with a solution. Please help.
Here is the javascript code:
export default class AccountTab extends LightningElement {
@api recordId;
@api accountList;
@wire(getAccounts, {recordId:'$recordId'})
wiredAccounts({data,error}){
if(data){
this.accountList = data;
console.log('current record id : '+this.recordId);
this.error=undefined;
}else if(error){
this.error=error;
this.accountList=undefined;
}
}
}
Please try this :
export default class AccountTab extends LightningElement {
@api recordId;
@api accountList = [];
@wire(getAccounts, {recordId:'$recordId'})
wiredAccounts({data,error}){
if(data){
this.accountList = data;
console.log('current record id : '+this.recordId);
this.error=undefined;
}else if(error){
this.error=error;
this.accountList=[];
}
}
}
Tried this but still getting undefined.
Is there any value in data variable?
Also please attach screenshot and HTML.