Topics for this chapter:
- Accessing Attributes In Controller
- Get and Set methods
- Find a component using aura:id
From chapter 6, we have learned about attributes, their usage and how one can access these attributes in the component markup using expressions.
In this chapter, we will learn how you can access these attributes value in the controller file.
Below is the way to access or get the value of an attribute in the controller file:
component.get("v.showNew"); //showNew is the attribute name from CarSearchForm component file
To set attribute value from the controller file:
aura:id defines the uniqueness of your HTML/Aura component in component markup. You can access these components in the controller file using find method:
component.find("carType");//carType is aura:id of aura:select element in CarSearchForm component
You can also access the attribute value of these components. For ex, if you want to access currently selected option of aura:select component, you can do this like below:
Lightning Component Development Day4 - Use Attributes In Controller, System Events, Debugging, SOQL
Access Attribute And Markup In Controller