Topics for this chapter:
- Inheritance In Aura Component
Similar to all other modern framework and programming languages, the Lightning framework also supports Inheritance. Using inheritance is one way to share the common code between multiple components.
Inheritance in Lightning allows you to inherit parent component’s attributes, body attributes, events, helper and client-side controller.
CarSearchForm.cmp
https://gist.github.com/b5a393036bedb0b94847c4bde1360650
CarSearchFormController.js
https://gist.github.com/4f32da34710ee3ced2ebb19631eab0d3
CarSearchFormHelper.js
https://gist.github.com/8e7514de0d49531ac82b62373487dc2c
In the above code, the Base component is an aura component which needs to be inherited by CarSearchForm component.
1. To make a component available for inheritance, you need to declare the abstract property to true.
2. In helper file, I have defined a few methods which will be called from CarSearchForm helper file.
3. To extend the Base component in CarSearchForm component, you need to extend it in the component.
4. In helper file, you can call Base component’s helper method simply referring them as helper.methodName().
Lightning Component Development Day5 - Server Side Controller, Apex, Inheritance In Lightning
Inheritance In Aura Component
Question
Your answer:
Correct answer:
Your Answers
Pingback: Interview Questions – Lightning Framework – Part 2 - Inheritance - SFDCFacts