You need to sign in to do that
Don't have an account?
Ashutosh Tripathi 72
LWC load data from Controller at first load of component
Hi
I want to set a variable from an apex class at the beginning of the component load.
I guess connctedCallBack should work for me. but as I am using a promise call there it's not working there, though if I write static code there, it works for me. What can I do to achieve this motive?
Code sample that I am using:
I want to set a variable from an apex class at the beginning of the component load.
I guess connctedCallBack should work for me. but as I am using a promise call there it's not working there, though if I write static code there, it works for me. What can I do to achieve this motive?
Code sample that I am using:
connectedCallback() { console.log('connectedCallback Called! '); //console.log(this.bookMarked); console.log('Item Id: ' + this.itemId); console.log('Checking if already bookmarked'); IsBookmarked({ sItemId: this.itemId }) .then(result => { console.log(result); console.log(this.buttonText); if (result) { this.buttonText = "Remove from bookmark"; this.updateButtonText('Remove from bookmark!'); } else { this.buttonText = "Bookmark Me!" this.updateButtonText('Bookmark Me!'); } console.log(this.buttonText); }) .error(error => { console.log('IsBookmarked Failed:' + error.body.message); }); }
B Karthickeyan
yes, you can instead of using connectedCallback() use constructor(). you can achieve.
Hope it helps you! Ashutosh Tripathi 72
@B Karthickeyan, I appreciate your reply. I have tried this method. But in this case, I won't able to access ItemId which is set from the community.