+ Start a Discussion
Tyler Tran 94Tyler Tran 94 

LWC - Variable is not defined

Can someone help me with this problem? When I load the component tab then it shows 2 errors: isVpbank is not defined and isHsbcBank is not defined

creditCard.html
<template>
    <template if:true={isVpbank}>
        <img class="image-card" src={vpbankImage}/>
    </template>

    <template if:true={isHsbcBank}>
        <img class="image-card" src={hsbcImage}/>
    </template>
    
    
    <div class="slds-m-around_medium">
        <template if:true={creditCard.data}>
            <template for:each={creditCard.data} for:item="cc">
                <p key={cc.Id}>{cc.Name}</p>
            </template>
        </template>
    </div>

</template>

creditCard.js
import { LightningElement, api, wire } from 'lwc';

import myResource from '@salesforce/resourceUrl/creditCard';
import getCreditCard from '@salesforce/apex/CreditCardController.getCreditCard';
import isVpBankCredit from '@salesforce/apex/CreditCardController.isVpBankCredit';
import isHsbcCredit from '@salesforce/apex/CreditCardController.isHsbcCredit';


const VP_BANK = myResource + '/credit-card-images/vp-bank.jpg';
const HSBC = myResource + '/credit-card-images/hsbc.jpg';

export default class CreditCard extends LightningElement {
    vpbankImage = VP_BANK;
    hsbcImage = HSBC;
    isVpbank = false;
    isHsbcBank = false;
    
    @wire(getCreditCard) creditCard;

    connectedCallback() {
        isVpBankCredit().then((result) => {
            this.isVpbank = result;
            console.log(isVpbank);
        });

        isHsbcCredit().then((result) => {
            this.isHsbcBank = result;
            console.log(isHsbcBank);
        });
    }
}

​​​​​​​
Best Answer chosen by Tyler Tran 94
ravi soniravi soni
hi Tyler,
check console log , public variable must be referance with "this".
console.log(this.isVpbank);
console.log(this.isHsbcBank);


let me know if it helps you and don't forget to marking it as best.
Thank you
 

All Answers

ravi soniravi soni
hi Tyler,
check console log , public variable must be referance with "this".
console.log(this.isVpbank);
console.log(this.isHsbcBank);


let me know if it helps you and don't forget to marking it as best.
Thank you
 
This was selected as the best answer
Tyler Tran 94Tyler Tran 94
Hi Veer doni,
Your solution, it is worked for me, thank you so much.