[SalesForce] Lightning Component record ID when component in Lightning Page

Ok, stupid question but I have searched and could not find this anywhere…

Q: How to you get (what is the expression syntax of) the ID of the record which is displaying the component / app?

I have read that I need to implement the interface force:recordTab here

Q: How is Lightning aware of what record you are on if you embed it in
Salesforce1? (i.e. how do you get the ID of the record you are on like
in a standard controller)?

A: Your component just needs to implement
the force:recordTab interface and the record and recordId will be
automatically injected when your component is wired into record home.

from the FAQ: https://developer.salesforce.com/page/Lightning_FAQ

Since found to be incorrect (see answer)

but beyond that I could find no documentation on this interface or anything in the lightning component developer guide that discusses this.

Basically, on init I need to grab the ID of the record whose detail page is being displayed.

Sorry for the newbie question but you would think something this simple would be out there in the open…..

Best Answer

Ok, I found it after doing some serious reading of the Winter '16 release.

You need to implement the interface:

force:hasRecordId

in your component and then you can access the record id via the following expression

{!v.recordId}

An example component would be:

<aura:component controller="CTRL_F_Controller" implements="flexipage:availableForAllPageTypes,force:hasRecordId">
<aura:attribute name="Account" type="Account"/>
    <ltng:require styles="/resource/bootstrap"/>
    <div class="bootstrap-sf1">
       <div class="container">
           <ui:outputText class="form-control" aura:id="recid" value="{!v.recordId}" />
        </div>
    </div>
</aura:component>
Related Topic