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
A G 27A G 27 

lightning inheritence

Hi,
I am learning lightning, can some1 pls help me.

I have created 2 components 1 is parent and the other is child and i am using child component in application so that it wud call parent indirectly.And if i call my parentcomponent in application its throwing me an error saying "It cant be instantiated". 

<--c:parentinherit-->
<aura:component extensible="true">
    <h3>Hi i am parent comp</h3>
</aura:component>

<--c:childinherit-->
<aura:component  extends="c:parentinherit">
    <h1> I am from child</h1>
</aura:component>


In my application i am using child component.I am not getting child component header tag output. Can any1 help?

<aura:application >
    
    Hi i am from application
    <c:childinherit/>
</aura:application>







 
Best Answer chosen by A G 27
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi ,
A sub component that extends a super component inherits the attributes of the super component. Use <aura:set> in the markup of a sub component to set the value of an attribute inherited from a super component.
It only  inherits all of the helper methods and attributes.But the markup in the component not get inherited.
Inorder to inherit compoent markup in parent component try this way.
<aura:component >
    <h1> I am from child</h1>
</aura:component>

<aura:component extensible="true">
    <h3>Hi i am parent comp</h3>
    <c:Childinherit/>
</aura:component>

<aura:application >
    
    Hi i am from application
    <c:parentinherit/>
</aura:application>

Please refer below links which might help you further.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/oo_whats_inherited.htm
https://developer.salesforce.com/blogs/developer-relations/2015/03/salesforce-lightning-components-by-example-component-extension.html

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards

All Answers

Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi ,
A sub component that extends a super component inherits the attributes of the super component. Use <aura:set> in the markup of a sub component to set the value of an attribute inherited from a super component.
It only  inherits all of the helper methods and attributes.But the markup in the component not get inherited.
Inorder to inherit compoent markup in parent component try this way.
<aura:component >
    <h1> I am from child</h1>
</aura:component>

<aura:component extensible="true">
    <h3>Hi i am parent comp</h3>
    <c:Childinherit/>
</aura:component>

<aura:application >
    
    Hi i am from application
    <c:parentinherit/>
</aura:application>

Please refer below links which might help you further.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/oo_whats_inherited.htm
https://developer.salesforce.com/blogs/developer-relations/2015/03/salesforce-lightning-components-by-example-component-extension.html

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards
This was selected as the best answer
A G 27A G 27
Hi,

I tried ur code,now also whats in parent component not coming in output
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi,
I think you missed something beacause I am able to see correct output.

User-added image
Please try again by pasting the same code.
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards
Hornick HanniganHornick Hannigan
Consider a scenario in which you have many components which call server side apex controller method from their helper function. So instead of writing callToServer method in all components helper function, you can create a component and mark it as extensible component and write callToServer function in helper function https://www.prepaidgiftbalance.vip/
A G 27A G 27
Hi Devi Chandrika,

I have a doubt here in child component we are not using extends in component,instead your calling child component in parent component itself? Why is it not working if i use extends in child component, Can u explain?
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi,
By inheriting we can call all of the helper methods, controller methods,attributes,events.But the component markup can not be accessed.
Here you are trying to access HTML markup of the component which is not  possible with inheritance.So it is not working by using extends.

Hope this helps you