0
<aura:component controller="LController"
                    implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:hasPageReference,lightning:actionOverride" 
                    access="global">
        <aura:attribute name="pageReference" access="public" type="Object"
                        description="Needed for IDE support, supplied by interface lightning:hasPageReference"/>
        <aura:attribute name="recordId" access="public" type="String" 
                        description="Needed for IDE support, supplied by interface force:hasRecordId"/>
        <aura:attribute name="contextData" access="private" type="Object" 
                        description="The context this component was loaded in"/>
        <aura:attribute name="legalLegitimationRecordTypeName" access="private" type="String" default="LegalLegitimation"/>
        <aura:attribute name="isRendered" type="Boolean" access="private" default="false"/>
        <aura:attribute name="legitimationRecordTypeId" type="String" access="private"/>
        <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

        <aura:if isTrue="{!v.isLegalLegitimationRendered}" >
            <lightning:overlayLibrary aura:id="legalOverLayLib"/>

            <!-- <c:CreateL  accountId="{!v.recordId}"></c:CreateL> -->
        <aura:set attribute="else">
            <c:LDetails pageReference2="{!v.pageReference}"></c:LDetails>
        </aura:set>
        </aura:if>
    </aura:component>

({
    doInit : function(component, event, helper) {
        helper.parsePageContext(component, component.get('v.pageReference'));
        helper.validateLegalLegitimation(component,  component.get('v.legalLegitimationRecordTypeName'));


    },


    createLegal: function(component, evt, helper) {
        console.log('Creating the l modal');
        var modalBody;
        $A.createComponent("c:CreateL", {},
           function(content, status) {
               if (status === "SUCCESS") {
                   modalBody = content;
                   component.find('legalOverLayLib').showCustomModal({
                       header: "Smiley Application Confirmation",
                       body: modalBody, 
                       showCloseButton: true,
                       closeCallback: function() {
                           alert('You closed the alert!');
                       }
                   })
               }
           })
    }
})

I am trying to call the function 'createL' inside aura if rather than directly calling the component because I want to show this component in modal. But when I use aura:method inside aura:if I get error. But How do I solve this ? Can some one give me some pointers ?

4
  • @ you have to clarify 1 thing here? 1.when you want call "createL" create component function -- init or any other button click ? if button click where did you put your button? i think what ever you added code in your question is not your full code. and more ever what error you got? i am not able to replicate your issue with your code
    – sdandamud1
    May 15, 2019 at 15:18
  • I do not want a button but rather call the function so that I can dynamically create my component and show that in modal window using lightning:overlayLibrary. It is my full code May 15, 2019 at 15:23
  • as your comment "I do not want a button but rather call the function" -- means do you want call function for showmodal from doInit? when "v.isLegalLegitimationRendered" is become a true?
    – sdandamud1
    May 15, 2019 at 15:30
  • Yes, that's right May 15, 2019 at 15:33

1 Answer 1

1

You can call create component function from your doInit when v.isLegalLegitimationRendered == true, like below your sample code.

cmp

<aura:component controller="LController"
                implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:hasPageReference,lightning:actionOverride" 
                access="global">
    <aura:attribute name="pageReference" access="public" type="Object"
                    description="Needed for IDE support, supplied by interface lightning:hasPageReference"/>
    <aura:attribute name="recordId" access="public" type="String" 
                    description="Needed for IDE support, supplied by interface force:hasRecordId"/>

    <aura:attribute name="legitimationRecordTypeId" type="String" access="private"/>
     <aura:attribute name="isLegalLegitimationRendered" type="Boolean" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <lightning:overlayLibrary aura:id="legalOverLayLib"/>

    <aura:if isTrue="{!v.isLegalLegitimationRendered}" >


        <!-- <c:CreateL  accountId="{!v.recordId}"></c:CreateL> -->
    <aura:set attribute="else">
        <c:LDetails pageReference2="{!v.pageReference}"></c:LDetails>
    </aura:set>
    </aura:if>
</aura:component>

controller.js

({
doInit : function(component, event, helper) {
    helper.parsePageContext(component, component.get('v.pageReference'));
    helper.validateLegalLegitimation(component,  component.get('v.legalLegitimationRecordTypeName'));
    if(component.get("v.isLegalLegitimationRendere")){
    $A.createComponent("c:CreateL", {},
           function(content, status) {
               if (status === "SUCCESS") {
                   component.find('legalOverLayLib').showCustomModal({
                       header: "Smiley Application Confirmation",
                       body: content, 
                       showCloseButton: true,
                       closeCallback: function() {
                           alert('You closed the alert!');
                       }
                   })
               }
           })
  }
},
})

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .