[SalesForce] Lightning Component Helper – Passing Data

I have been reading and I can't seem to understand one part of the component – controller – helper – apex combo.

If I have a lightning component that is connected to an apex controller…I am confused how an attribute such as <aura:attribute name="ahg" type="object" /> would know any data. Where is it pulling the data from? What is the value of agh? I can see from a console.log that ahg has a value. I just don't understand how it is set.

Secondly, what is the value of parameters component, event, helper in the lightning component's controller's function? Is the param component the object? Is there an easy way to console.log() the event? Right now I get back [Object, Object]. When I: event.toString() or console.dir() I get back useless information.

My end goal is to get the value of a custom object's name and hid/display a div dependent on the value. I need to be able to see the values and know what I am playing with so that I can then pass the appropriate data to the apex controller (if needed).

Component

<aura:component controller="CommunityAccountListController" implements="forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="ahg" type="object" />

Controller

({
    doInit : function(component, event, helper) {

enter code here

Best Answer

Ok, I see two questions here:

1) Where are the attribute values coming from

The value of an aura:attribute can really come from four places

  • It can be set in javascript component.set('v.ahg', myVariable)
  • It can be passed as a parameter to the component <c:myComponent ahg="myValue" />
  • It can be defined by default in the attribute <aura:attribute name="ahg" type="String" value="a String">
  • it can come from the flexipage itself (via a Design Attribute)

More details here. It's hard to apply this to your use case. I don't have enough detail to dig more

2) What are the values of component, event, helper

The three values contain, in order,

  • a reference to the component JS. You would use this for various things, like setting/getting attribute values (see my example above) or finding nodes by their "aura:id" (component.find('myComponentId'))
  • a reference to the event being fired, if any. You would use this to catch events and their parameters (event.getParam('myValue'))
  • a reference to the helper JS You would use this to call helper functions (helper.doSomething())

There are a bazillion more uses for the three classes, but these are basics of what you can do with each. You can start here and read the documentation from there.

Related Topic