I am calling lwc method from aura. It gives me error: Cannot read properties of undefined (reading 'then')]. Here is my code. There were some complex logic, but it gives the same error with just returning true;
export default class LwcComponent extends LightningElement {
@api lwcMethod() {
return true; //changed to "return Promise.resolve(true)";
}
Aura
<aura:component>
<aura:handler name="init"
value="{!this}"
action="{!c.onInit}"
/>
<c:LwcComponent aura:id="lwcComponent"/>
</aura:component>
({
onInit: function (component, event, helper) {
helper.doInit(component);
}
})
({
doInit: function (component) {
component.find('lwcComponent').lwcMethod()
.then($A.getCallback(function (response) {
alert(response);
}));
},
})
UPD:I debugged and it seems that method even is not called
Promise
for.then
to work.