function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohith SundarMohith Sundar 

Hello Playground lightning trailhead

Hi All , 

Below is the code snippet  code which is highlighted in bold is not executing, i logged into to iphone then checked , code is not returning true for {!v.messages[0] can someone help pls , what wrong going through 

<aura:component >
    <aura:attribute name="messages" type="List"
                    default="['you look nice today.',
                              'Great whether we are having.',
                              'How are you?']"/>
    
    <h1> Hello Playground</h1>
    <p> Silly fun with attributes and expressions</p>
    <br></br>
    <h2> List Items</h2>
    <br></br>
    <p> <c:hellomessage message="{!v.messages[0]}"/> </p>
    <p> <c:hellomessage message="{!v.messages[1]}"/> </p>
    <p> <c:hellomessage message="{!v.messages[2]}"/> </p>
     <br></br>
    <h2> List iteration </h2>
    <br> </br>
    <aura:iteration items="{!v.messages}" var="msg">
        <p> <c:hellomessage message="{!msg}"/> </p>
    </aura:iteration>
     <br></br>
    <h2> conditional Expressions and Global value providers</h2>
    <br></br>
    <aura:if isTrue="{!$Browser.isIPhone}">
        <p> <c:hellomessage message="{!v.messages[0]}"/> </p>
    <aura:set attribute="else">
        <p> <c:hellomessage message="{!v.messages[1]}"/>  </p>    
    </aura:set>
    </aura:if>

</aura:component>
Pavit SiddhuPavit Siddhu

Hello You can check it on controller by var isIphone=$A.get("$Browser.isIPhone") and create a attribute assign value to attribute, use the attribute instead of direct in component.

<aura:attribute name="isIphone" type="boolean" >
<aura:if isTrue="{!$Browser.isIPhone}">
        <p> <c:hellomessage message="{!v.messages[0]}"/> </p>
    <aura:set attribute="else">
        <p> <c:hellomessage message="{!v.messages[1]}"/>  </p>    
    </aura:set>
    </aura:if>

var isIphone=$A.get("$Browser.isIPhone")
component.set("v.isIphone", isIphone);

Maybe it works

Mohith SundarMohith Sundar
Hi , 

for the below code should i create a controller how do i use it , could you please guide me 

var isIphone=$A.get("$Browser.isIPhone") 
component.set("v.isIphone", isIphone);
 
Pavit SiddhuPavit Siddhu

<aura:attribute name="isIphone" type="boolean" >

<aura:handler name="init" value="{!this}" action="{!c.doInit}" />

<aura:if isTrue="{!v.isIPhone}">
        <p> <c:hellomessage message="{!v.messages[0]}"/> </p>
    <aura:set attribute="else">
        <p> <c:hellomessage message="{!v.messages[1]}"/>  </p>    
    </aura:set>
    </aura:if>

component is like this

 

({
    doInit: function(component, event, helper) {
        var isIphone=$A.get("$Browser.isIPhone") 
        component.set("v.isIphone", isIphone);
    }
})
Put in controller