You need to sign in to do that
Don't have an account?
Al Be
Lightning Component: doInit is not defined
Hello!
I have a Lightning Component PortalHeader
PortalHeader.cmp looks like this:
Any idea of what is going on here and why am I getting this error?
Thank you very much!
I have a Lightning Component PortalHeader
PortalHeader.cmp looks like this:
<aura:component controller="currentUserInfoCtrl" description="portalHeader" implements="forceCommunity:availableForAllPageTypes" access="global"> <aura:attribute name="userInfo" type="user"></aura:attribute> <aura:handler name="init" value="{!this}" action="{!c.initMe}"/> <div id="ui-wrapper"> <div class="container"> ...PortalHeaderController.js:
({ initMe : function(component, event, helper) { var action = component.get("c.fetchUser"); ...and I am getting an error:
> ***doInit** is not defined throws at https://.../AP/s/components/c/**PortalHeader.js**:30:17*Please note:
- I don't call it doInit I call it initMe function
- even if I rename it to doInit I still get the same error.
- There is no PortalHeader.js file there is PortalHeaderController.js and PortalHeaderHelper.js
Any idea of what is going on here and why am I getting this error?
Thank you very much!
Trick was to move all the initialization to the Helper file
And then call it once from doInit and again from the event
All Answers
Hi Alexei
Where are you coding?
- Developer Console
- Visual Code
It looks like you have the file and it is calling doInit method.If you make changes in the component, make sure you also change in the Controller too.
Can you share the folder structure of your component?
Hi,
Please use the below code.
Please mark it as the Best Answer if your queries are solved.
Thanks
Yes I do have a call to doInit() method from Event listener (see below).
Problem is: doInit() is right there in the PortalHeaderController.
I can rename it ot initMe() in both places and get an error about initMe.
Also I should mention: error is happening in the Experience Builder, or when I add component to a page. Some times this error keeps popping up multiple times. I keep clicking [OK] and eventualy it goes away. and I can edit my page layout.
When I publish to the site or save the page, my component seems to be working correctly.
It seems to be a problem of the develpment tools.
Is there a way to correct it?
Thanks!
Where is the handler define for the doInit Method?
In the PortalHeaderController.js
Trick was to move all the initialization to the Helper file
And then call it once from doInit and again from the event