Skip to main content

Get started with Simple Lightning Web Component(Bike Card)

Lightning web component HTML files all include the template tag. The template tag contains the HTML that defines the structure of your component. Let’s look at the HTML for a simplified version of the component.

Paste the following into app.html (replacing any existing HTML in the file).

bikeCard.html
<template>
<div id="waiting" if:false={ready}>Loading..</div>
<div id="dispaly" if:true={ready}>
<div>Name: {name}</div>
<div>Description: {description}</div>
<div>Category: {category}</div>
<div>Material: {material}</div>
<div>Price: {price}</div>
<div><img src={pictureURL}/></div>
</div>
</template>

The identifiers in the curly braces {} are bound to the fields of the same name in the corresponding JavaScript class.
Here’s a JavaScript file to support this HTML. Paste this into bikeCard.js.

bikeCard.js
import {LightningElement} from 'lwc';
export default class bikeCard extends LightningElement{
name = 'Hero';
description = 'A nice bike build for comfort';
category = 'BiCycle';
material = 'Steel';
price = '100000';
pictureURL = 'https://s3-us-west-1.amazonaws.com/sfdc-demo/ebikes/electrax4.jpg';

ready = false;
connectedCallback(){
setTimeout(() =>{
this.ready = true;
}, 3000)
}
}

bikeCard.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>48.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
The component configuration file with the extension .js-meta.xml. This file provides metadata for Salesforce, 
including the design configuration for components intended for use in Lightning App Builder.
Required
apiVersion binds the component to a Salesforce API version.
isExposed (true or false) makes the component available from other namespaces. 
Only set this to true to make a component usable in a managed package or by Lightning App Builder in another org.

Optional
targets specify which types of Lightning pages the component can be added to in the Lightning App Builder.
targetConfigs let you specify behavior specific to each type of Lightning page, 
including things like which objects support the component.

The Preview now shows a bike with some details.

Preview:

Comments

Popular posts from this blog

Disable Document Download in Salesforce

Disable downloads for certain users based on the name of the file uploaded to Salesforce. We can use the following example code inside of a Apex class. This code essentially prevents files whose file name starts off with Kaipu- from being downloaded by anyone whose user role’s developer name is not Kaipu_Sales. Modify this code to suit your own purpose. Based on Role: public class ContentDownloadHandlerFactoryImpl implements Sfc.ContentDownloadHandlerFactory {    public Sfc.ContentDownloadHandler getContentDownloadHandler(List<ID> ids, Sfc.ContentDownloadContext context) {      // See if the user has the Kaipu Sales role (based on developer name field).      Boolean isSecretUser = [        SELECT Id        FROM UserRole        WHERE ID = :UserInfo.getUserRoleId()          AND DeveloperName = ' Kaip...

Commonly asked Lightning Developer Interview Questions & Answers

1. Where can we use Lightning Components? We can use Lightning Components in the following places: Drag-and-drop Components in the Lightning App Builder and Community Builder. Add Lightning Components to Lightning Pages. Add Lightning Components to Lightning Experience Record Pages. Launch a Lightning Component as a Quick Action Override Standard Actions with Lightning Components Create Stand-Alone Apps 2. How do you build Lightning Components? We can build Lightning Components using two programming models: the Lightning Web Components model, and the original Aura Components model. 3. How can you create Lightning Record Pages in Salesforce, and what are the different types? We can make use of Lightning App Builder for creating Lightning Record Pages, to create the following three types of pages: App Page Home Page Record Page 4. What options are there for Lightning Record Page assignment? “Lightning Pages” can be assigned at three different levels: The org default App default – this ov...