Newer Version Available

This content describes an older version of this product. View Latest

Setting Attributes Inherited from a Super Component

Use <aura:set> in the markup of a sub component to set the value of an inherited attribute.

Let's look at an example. Here is the docsample:setTagSuper component.

1swfobject.registerObject("clippy.codeblock-0", "9");<!--docsample:setTagSuper-->
2<aura:component extensible="true">
3    <aura:attribute name="address1" type="String" />
4    setTagSuper address1: {!v.address1}<br/>
5</aura:component>
6

docsample:setTagSuper outputs:

1setTagSuper address1:

The address1 attribute doesn't output any value yet as it hasn't been set.

Here is the docsample:setTagSub component that extends docsample:setTagSuper.

1swfobject.registerObject("clippy.codeblock-2", "9");<!--docsample:setTagSub-->
2<aura:component extends="docsample:setTagSuper">
3    <aura:set attribute="address1" value="808 State St" />
4</aura:component>
5

docsample:setTagSub outputs:

1setTagSuper address1: 808 State St

sampleSetTagExdocsample:setTagSub sets a value for the address1 attribute inherited from the super component, docsample:setTagSuper.

This usage of <aura:set> works for components and abstract components, but it doesn’t work for interfaces. For more information, see Setting Attributes Inherited from an Interface.

Warning

If you’re using a component by making a reference to it in your component, you can set the attribute value directly in the markup. For example, docsample:setTagSuperRef makes a reference to docsample:setTagSuper and sets the address1 attribute directly without using aura:set.

1swfobject.registerObject("clippy.codeblock-4", "9");<!--docsample:setTagSuperRef-->
2<aura:component>
3    <docsample:setTagSuper address1="1 Sesame St" />
4</aura:component>
5

docsample:setTagSuperRef outputs:

1swfobject.registerObject("clippy.codeblock-5", "9");setTagSuper address1: 1 Sesame St
2