Newer Version Available
Component Attributes
Use the <aura:attribute> tag to add an attribute to the component or app. Let’s look at the following sample, helloAttributes.app:
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<aura:application>
18 <aura:attribute name="whom" type="String" default="world"/>
19 Hello {!v.whom}!
20</aura:application>
21
22All attributes have a name and a type. Attributes may be marked as required by specifying required="true", and may also specify a default value.
In this case we've got an attribute named whom of type String. If no value is specified, it defaults to "world".
Though not a strict requirement, <aura:attribute> tags are usually the first things listed in a component’s markup, as it provides an easy way to read the component's shape at a glance.
Attribute names must start with a letter or underscore. They can also contain numbers or hyphens after the first character.
Now, append ?whom=you to the URL and reload the page. The value in the query string sets the value of the whom attribute. Supplying attribute values via the query string when requesting a component is one way to set the attributes on that component.
Expressions
helloAttributes.app contains an expression, {!v.whom}, which is responsible for the component's dynamic output.
Attribute Validation
We defined the set of valid attributes in helloAttributes.app, so the framework automatically validates that only valid attributes are passed to that component.
Try requesting helloAttributes.app with the query string ?fakeAttribute=fakeValue. You should receive an error that helloAttributes.app doesn’t have a fakeAttribute attribute.