function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Renuka kamble 10Renuka kamble 10 

Hi All, I want to open another lightning component on click of button. Please help in this.

I am trying to open another component on click of button but i am getting error as "Cannot read property 'newComponentAsync' of undefined".

Below is my code-

Component-
<button class="slds-button slds-button--neutral" onclick="{!c.gotoURL}">Open Another Component</button>

Controller-
gotoURL : function(component, event, helper) {
        var destination ="markup://c:SampleComponent";
        $A.componentService.newComponentAsync(this,
            function(view) {
              var content = component.find("content");
              content.set("v.body", view);
              }, 
              {
                 componentDef: destination,
                          }, component);
    }

Please help. 
Priyankar PakhiraPPPriyankar PakhiraPP
Have you tried with " e.force:navigateToComponent " however this is a beta version and limitiation is you can use it only for Lightning Experience and Salesforce1 . 

please go through this below link

https://force-base.com/2016/11/06/lightning-components-navigation-re-defined-in-winter17-woooo-hooooo/
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_navigateToComponent.htm

Happy Lightning learning.