You need to sign in to do that
Don't have an account?

attribute value in span tag in lightning
I have a piece of code which will display number of stars depending upon the attribute value as follows
<aura:attribute name="ratingValue" type="List"/>
<aura:iteration items="{!v.ratingValue}" var="rating" indexVar="indx">
<aura:if isTrue="{!rating == 1}">
<b>*</b>
</aura:if>
<aura:if isTrue="{!rating == 2}">
<b>* *</b>
</aura:if>
<aura:if isTrue="{!rating == 3}">
<b>* * *</b>
</aura:if>
<aura:if isTrue="{!rating == 4}">
<b>* * * *</b>
</aura:if>
</aura:iteration>
<span>{!v.ratingValue} ratings</span> <lightning:icon iconName="standard:sales_path" size="x-small"/>
In the controller of the above component
({
doInit : function(component, event, helper) {
component.set("v.ratingValue",3);
}
})
Based on the attribute value I am able to display the stars but {!v.ratingValue} inside the component is not showing any value even though it is set in the controller.
Please let me know if some issue in my code with some correct piece of working code.
thanks
meghna
<aura:attribute name="ratingValue" type="List"/>
<aura:iteration items="{!v.ratingValue}" var="rating" indexVar="indx">
<aura:if isTrue="{!rating == 1}">
<b>*</b>
</aura:if>
<aura:if isTrue="{!rating == 2}">
<b>* *</b>
</aura:if>
<aura:if isTrue="{!rating == 3}">
<b>* * *</b>
</aura:if>
<aura:if isTrue="{!rating == 4}">
<b>* * * *</b>
</aura:if>
</aura:iteration>
<span>{!v.ratingValue} ratings</span> <lightning:icon iconName="standard:sales_path" size="x-small"/>
In the controller of the above component
({
doInit : function(component, event, helper) {
component.set("v.ratingValue",3);
}
})
Based on the attribute value I am able to display the stars but {!v.ratingValue} inside the component is not showing any value even though it is set in the controller.
Please let me know if some issue in my code with some correct piece of working code.
thanks
meghna
Use below code:
Regards,
Khan Anas
All Answers
Greetings to you!
Your code looks good to me. I have checked in my org and it is working as expected. I suggest you to check init handler in component as lightning is based on aura framework which is a type of JavaScript and JavaScript is case sensitive so lightning is case sensitive.
Component:
Controller:
Application:
Screenshot:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
In the doInit event if I am setting a value of 3 then the output should look like this. I am getting the stars based on the value set in the attribute but the value of attribute I want as {!v.ratingValue} i.e 3 ratings
* * *
3 ratings
thanks
meghna
Use below code:
Regards,
Khan Anas
This worked. I was looking for this piece of info.
thanks very much
meghna