0

I have such code:

JS

    @track messageBody;

    @wire(getDataFromController) 
    emailTemplate ({ error, data }) {
        if (data) {
            this.messageBody = data[0].Body; //EmailTemplate Object Body field value
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.record = undefined;
        }
    };

    get body(){
        return this.messageBody;
    };

    handleEmailTextChange(event){
        this.messageBody = event.target.value;
     };

HTML

            <template if:true={emailTemplate.data}>
                <lightning-textarea name="emailBody" label="Email Body" value={body} onchange={handleEmailTextChange}></lightning-textarea>
            </template>

When I click my quick action, I see all fields except this part. I suppose that is why if:true={emailTemplate.data}. But in debug mode I see my data.

enter image description here

What I made wrong?

1 Answer 1

1

I think you got confused with params.

if:true in LWC only expects value in true and false. And emailTemplate wired method error and data is not something which should be referred like you are referring.

So your <template if:true={emailTemplate.data}> should change to :

<template if:true={valueAvailable}>


valueAvailable = false;

@wire(getDataFromController) 
emailTemplate ({ error, data }) {
    if (data) {
        this.messageBody = data[0].Body; //EmailTemplate Object Body field value
        this.error = undefined;
        this.valueAvailable = true;
    } else if (error) {
        this.error = error;
        this.record = undefined;
    }
};
1
  • Thank you. Now everything is great!
    – Yauheni
    Jun 27 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.