HOW TO USE VALUE PROVIDERS IN SALESFORCE LIGHTNING ?

HOW TO USE VALUE PROVIDERS IN SALESFORCE LIGHTNING ?

VALUE PROVIDERS

In this episode, we have something different to discuss i.e. salesforce lightning value providers.
Let's get started, So value providers are a way to access data.

Value providers encapsulate related value together, similar to how an object encapsulates properties and methods.
The value providers for a component are v(view) and c(controller).

A component's view refers to its attribute set.

A component's controller enables you to wire up event handlers and action for the components. It's where you control your component's logic.

All components have value providers but aren't required to have a controller. Both value providers are created automatically when defined for a component.
In simple words, the salesforce value provider provides information about your browser, location, your device information etc.

Let's understand global value providers.
Global Value Providers :
Global value providers are value and methods that a component can use in the lightning expression.

Here are some global value providers you need to know :

globalId:
It returns the global ID for a component has a unique globalId, which is generated runtime-unique ID of the component instance.

$Browser: It returns information about the hardware and operating system of the browser accessing the application.

$Label: It enables you to access labels stored outside your code.

$Locale: It returns information about the current user's preferred locale.
Now we are more interested to discuss $Browser and $Locale.
So let's see attributes of $Browser :

isAndroid:
It indicates whether the browser is running on an Android device (true) or not (false).

isIOS: It is not available in all implementations. It indicates whether the browser is running on an iOS device (true) or not (false).

isIPhone: It indicates whether the browser is running on the iPhone (true) or not (false).

isWindowsPhone: It indicates whether the browser is running on a windows phone (true) or not (false).
FORM FACTOR ATTRIBUTE :
It returns a Form Factor enum value based on the type of hardware the browser is running on

DESKTOP for a desktop client

PHONE for the phone including a mobile phone with a browser and a          smartphone

TABLET for a tablet client (for which isTablet returns True)
Let's Understand with an example :
Example Lightning Component :
=================================================
<aura:component>
  Browser running on Tablet: {!$Browser.isTablet}
   <br></br>
    Is it running on IPhone: {!$Browser.isIPhone}
    <br></br>
     Is it running on Android: {!$Browser.isAndroid}
     <br></br>
I am Running on : {!$Browser.FormFactor}
</aura:component>
=================================================

Output :
=================================================
Browser running on Tablet: false
Is it running on IPhone: false
Is it running on Android: false
I am Running on DESKTOP
=================================================

Now we have attributes of
$Locale global value providers.

$Locale: 
The $Locale global value provider returns information about the current user's preferred locale.

Country: The ISO 3166 representation of the country code based on the language locale.

Currency: The currency symbol.

Timezone: The time zone ID.

NumberFormat: Gives number formatting.
Let's understand with an example :
Example Lightning Component :
=================================================
<aura:component>
  Language : {!$Locale.language}
   <br></br>
   TimeZone : {!$Locale.timezone}
     <br></br>
      Number Format : {!$Locale.NumberFormat}
       <br></br>
        Currency : {!$Locale.Currency}
        <br></br>
</aura:component>
=================================================

Output:

=================================================
Language : en

TimeZone : America / Los-Angeles
Number Format : #, ##0, ###
Currency : $
=================================================

Coool !! In this way, you can use value providers in salesforce lightning component.

In the new episode, we will discuss standard salesforce component and force.com component.

WOHOOO !! YOU HAVE JUST COMPLETED LIGHTNING VALUE PROVIDERS EPISODE
If you like this salesforcekid learning platform please let me know in the Comment section...Also, Share with your salesforce folks wish you 
Happy learning ☁️⚡️ (Learn. Help. Share.)

<< PREVIOUS

HOW TO USE VALUE PROVIDERS IN SALESFORCE LIGHTNING ? HOW TO USE VALUE PROVIDERS IN SALESFORCE LIGHTNING ? Reviewed by on Rating: 5

No comments:

HELP !! SHARE !! SUGGEST !!

Powered by Blogger.