A lightning component: helloPlayground
<aura:component>
<aura:attribute name="messages" type="String"/>
<p>Message of the day: {!v.message}</p>
</aura:component>
I can pass the attribute value in a lightning App like:
<aura:application >
<c:helloPlayground messages="['You look nice today.']"/>
</aura:application>
2nd Lightning Component: helloObjectAttrComponent
<aura:component >
<aura:attribute name="item" type="Camping_Item__c" required="true"/>
<lightning:formattedNumber value="{!v.item.Quantity__c}" style="decimal"/>
<lightning:formattedNumber value="{!v.item.Price__c}" style="Currency"/>
</aura:component>
How do I pass the record in the lightning App below like the way I passed String
? Is this even possible or the records can be only passed through apex controller?
<aura:application >
<c: helloObjectAttrComponent xxxxxx />
</aura:application>
Best Answer
You do it the exact same way:
You can initialize a record in the same manner as most other objects:
Note that if you pass in the value directly, as you did in the first example:
Then the object would be immutable (can't be edited).