You need to sign in to do that
Don't have an account?
Shivangi Verma
How to Create clickable images in lightning component ?
Hi All,
I have a requirement to create a lightning component in which i want to display the images as links. On clicking the image an action should be called from the Js controller. Please let me know how to do this in lightning.
I have a requirement to create a lightning component in which i want to display the images as links. On clicking the image an action should be called from the Js controller. Please let me know how to do this in lightning.
Using the attribute 'title' instead of value worked for me.
Component : Controller :
Thank you to all for your help.
Shivangi
All Answers
Greetings to you!
You can place the image in a span or div:
Controller:
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
1 . Just place the contents of your component in a span or div:
2 . Call it a a tag
I want to basically use icon instead of image. Currently i have a button below the icon and users have to click the button to call the function. Is there a way i can associate icon with click event since i am using the 'event.getSource().get("v.label")' to fetch the value from the button and use it as the record type to create new record. I want to associate some event to the icon. Please see my current code below :
Component :
<div class="slds-align_absolute-center">
<lightning:icon iconName="custom:custom20" size="large" />
</div>
<div class="slds-align_absolute-center">
<lightning:button class="slds-button" label = "XYZ" onclick = "{!c.createRecord}" variant="brand" />
</div>
here XYZ is the record type for the create event.
Controller :
createRecord: function(component, event, helper) {
var createRecordEvent = $A.get("e.force:createRecord");
var RecTypeID = event.getSource().get("v.label");
}
Thanks
Shivangi
Firstly you have to add image to static resource and then follow the below code it may be helpful for you: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
If you want the clickable icon in the lightning component then also you can place the icon component in a span or div:
If you want an icon on a button you can use iconName attribute on lightning:button:
Regards,
Khan Anas
I had tried button icon but the problem with button icon is it is too small. Even the max size is not that large as the icon so i used the icon by itself. How can I capture the event values from the icon. I tried the following snippet but it is not working. I want to fetch the record type name value from the icon somehow.
Component : here 'XYZ' is the record type
Controller :
Thanks
Shivangi
Using the attribute 'title' instead of value worked for me.
Component : Controller :
Thank you to all for your help.
Shivangi
How do we use our own custom icon instead of the available custom icons? is it possible?
Thanks,
Sathiya