+ Start a Discussion
shweta kumari 25shweta kumari 25 

call a lightning component from a custom button

I am not an expert in lightning components, so I had to post this question.

In lightning, I have an app page. There a is a primarycomponent kept on the lightning page.

PrimaryComponent.cmp
----------------------------
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable"
                access="global" >
 <lightning:button label="Neutral" 
                             title="Neutral action" 
                             onclick="{!c.handleF1Comp}"/>
</aura:component/>

Now I have another component say F1Comp.cmp

<aura:component implements="flexipage:availableForAllPageTypes"
                access="global" >
 <h1> I am F1 Comp </h1>
   </aura:component/>

My requirement is when I click the button In primarycomponentit should call the f1Comp.

How to achieve this?

Please eloborate and suggest approaches.
Thanks
shwet
Raj VakatiRaj Vakati
You need to use lightning:isUrlAddressable interface extends the lightning:hasPageReference interface. A component that implements lightning:isUrlAddressable then gets access to the page state through the pageReference attribute. The page state is a representation of the current URL query parameters.


Refer this link 

https://developer.salesforce.com/docs/component-library/bundle/lightning:isUrlAddressable/documentation
Raj VakatiRaj Vakati
Code
F1Comp.cmp
<aura:component implements="flexipage:availableForAllPageTypes,lightning:isUrlAddressable"
                access="global" >
 <h1> I am F1 Comp </h1>
   </aura:component/>
 
PrimaryComponent.cmp
----------------------------
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable"
                access="global" >
  <aura:attribute name="pageReference" type="Object"/>
 <aura:handler name="init" value="{! this }" action="{! c.init }"/> 
<lightning:navigation aura:id="navService"/> 
<lightning:button label="Navigate" onclick="{!c.handleClick}"/>
</aura:component/>

Controller : 

​

    init : function(component, event, helper) {
        var pageReference = {
            type: 'standard__component',
            attributes: {
                componentName: 'c__F1Comp',
            },
            state: {
                 
            }
        };
        component.set("v.pageReference", pageReference);
     },
     handleClick: function(component, event, helper) {
        var navService = component.find("navService");
        var pageReference = component.get("v.pageReference");
        event.preventDefault();
        navService.navigate(pageReference);
    }

 
Abigail PenningtonAbigail Pennington
I hope that all the salesforce's can find solutions to our problems..

_____________________________________________________
https://www.mcdvoice.onl

 
Ajay K DubediAjay K Dubedi
Hi shweta,

Try this one out:
PrimaryComponent.cmp-->
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable"
                access="global" >
 <lightning:button label="Neutral" 
                             title="Neutral action" 
                             onclick="{!c.handleF1Comp}"/>
</aura:component/>
PrimaryComponentController.js--->
({ handleF1Comp:function (c ,e, h) {
        var evnt = $A.get("e.force:navigateToComponent");
        evnt.setParams({
            componentDef  : "c:F1Comp",
            componentAttributes: { }
    });
        evnt.fire();
    }
})
F1Comp.cmp------>
<aura:component implements="flexipage:availableForAllPageTypes"
                access="global" >
 <h1> I am F1 Comp </h1>
   </aura:component/>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
 
brad leebrad lee
You explained in a detailed way about this and thanks for sharing this to us. Check this for more details about the customer feedback survey. www.homedepot.com/survey (https://succeedfoundation.org/homedepot-survey)
zainab khanzainab khan
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable"
                access="global" >
 <lightning:button label="Neutral" 
                             title="Neutral action" 
                             onclick="{!c.handleF1Comp}"/>
</aura:component/>
PrimaryComponentController.js--->
({ handleF1Comp:function (c ,e, h) {
        var evnt = $A.get("e.force:navigateToComponent");
        evnt.setParams({
            componentDef  : "c:F1Comp",
            componentAttributes: { }
    });
Please try this!!tellthebell (https://surveyforcustomers.com/tellthebell-com/)
joeytrib bianijoeytrib biani
hotmail login (https://hotmail.best/) You explained in a detailed way  walmartone (https://walmartone.tech/) Please try this!!tellthebe https://survey-feedback.net/ above solution helpful. If it does, please mark as Best Answer to help others too.
johnson eaterjohnson eater
access into iCloud Photos on iPhone (https://icloudlogin.co/)
johnson eaterjohnson eater
mkolq lolsmkolq lols
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable"
04                access="global" >
05  <aura:attribute name="pageReference" type="Object"/>
06 <aura:handler name="init" value="{! this }" action="{! c.init }"/>
07<lightning:navigation aura:id="navService"/>
08<lightning:button label="Navigate" onclick="{!c.handleClick}"/>
09</aura:component/>
Webmail (http://www-hotmail-com.email/)
johns martjohns mart
halaman jethohalaman jetho
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable"
                access="global" >
 <lightning:button label="Neutral" 
                             title="Neutral action" 
                             onclick="{!c.handleF1Comp}"/>
</aura:component/>
PrimaryComponentController.js--->
({ handleF1Comp:function (c ,e, h) {
        var evnt = $A.get("e.force:navigateToComponent");
        evnt.setParams({
            componentDef  : "c:F1Comp",
            componentAttributes: { }
    }); 

i have use on :  hotmail.com login  (https://hotmail-loign.com/www-hotmail-com/)
tony stark 80tony stark 80
Try this one out:
PrimaryComponent.cmp-->
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable"
                access="global" >
 <lightning:button label="Neutral" 
                             title="Neutral action" 
                             onclick="{!c.handleF1Comp}"/>
</aura:component/>
 ePayItOnline (https://ranvex.com/)
adam levine 35adam levine 35
Thanks for the post. Visit Wendy's restaurant and win cash offers and prices. Check our website for more information: Wendy's.com (https://talktowendysurvey.com/)
Billy BoudenBilly Bouden
you must need a coin supplyer for coin master game. Here it is: (https://coinmaster.breakingbio.com/)
Jerry BrottJerry Brott
Thanks for this knowledgable post. Getmyoffer.capitalone.com (http://getmyoffer.pro/) | Capital one Credit Card Details