0

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>

1 Answer 1

4

You do it the exact same way:

<c:helloObjectAttrComponent item="{!v.record}" />

You can initialize a record in the same manner as most other objects:

<aura:attribute name="record" type="Camping_Item__c" 
    default="{ 'sobjectType': 'Camping_Item__c', 'Quantity__c': 5, 'Price__c': 4.99 }" />

Note that if you pass in the value directly, as you did in the first example:

<c:helloObjectAttrComponent item="{ 'sobjectType': 'Camping_Item__c' }" />

Then the object would be immutable (can't be edited).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .