0

It is a complex issue so I'll try to descrive each steap as clearly as possible.

At first I hace this CMP that I 'll call "rootCMP".

EDIT:

This component is called from an event because it works as a right side bar and need to render it with parameters that comes from other components on the page. For this case parameter1 value comes with this event.

RootCMP

<aura:component controller="OController">
  <aura:attribute name="parameter1" type="String" />

  <div class="ASH2 slds-border_bottom" > TITLEt </div>
    <div class="H1" /> 
  <div>
      <!-- Page Content -->
    <div class="slds-text-heading_small slds-p-bottom_small">
      SUBTITLE1
    </div>

    <c:CMP_ListigItems parameter1="{!v.parameter1}"/>
  </div>
  <div>
    <!-- Page Content -->
    <div class="slds-text-heading_small slds-p-bottom_medium">
      SUBTITLE2
    </div>
    <c:CMP_Parent1 parameter1="{!v.parameter1}"/>
  </div>
/aura:component>   

This RootCMP calls to CMP_ListingItems who receives parameter1 from RootCMP

<aura:component>
  <aura:attribute name="label" type="String" />
  <aura:attribute name="itemsList" type="Items__c[]" />
  <aura:attribute name="parameter1" type="String" default=""/>

  <c:AS_GetItemsByParametery parameter1="{!v.parameter1}" items="{!v.itemsList}"/>

  <div class="slds-pill_container">
    <aura:iteration var="item" items="{!v.itemsList}">
      <c:AS_ITemPill item="{!item}" parameter1="{!v.parameter1}" />
    </aura:iteration>
  </div>
</aura:component>

The component AS_GetItemsByParameter is used to retrieve a list of items filtered by parameter1.

AS_GetItemsByParameter

<aura:component implements="force:appHostable,force:lightningQuickAction" controller="Controller" access="global">
parameter1 | {!v.strategyId}
  <aura:attribute name="parameter1" type="String" />
  <aura:attribute name="items" type="Item__c[]" />

  <aura:handler name="init" value="{!this}" action="{!c.onInit}" />
</aura:component>

As you can see in this CMP i'm printing the value of parameter1 and it is being showed in the screen. The issue starts in the controller.

AS_GetItemsByParameterController.js in the third line of the onInit method, you can see an alert to view the value of parameted1 but the value that it throws is undefined

({
  onInit: function(component, event, helper) {
    var action = component.get("c.getITemsByParameter");
    var parameter1 = component.get("v.parameter1");
    alert(JSON.stringify(parameter1));
    action.setParams({
      parameter1: parameter1
    });

    action.setCallback(this, function(response) {
      var state = response.getState();
      if (state === "SUCCESS") {
        var items = response.getReturnValue();
        component.set("v.items", items);
      } else {
        console.log("Failed with state: " + state);
      }
    });
    $A.enqueueAction(action);
  },

});

Assumptions:

  • The apex code who is called by the controller is working well for other methods.
  • The architecture of usng a component to retrieve things and other to list them is working in other components too.
4
  • 1
    can you please update u r question with how did you get v.parameter1 value in RootCMP? – sdandamud1 Nov 25 '19 at 13:03
  • @sdandamud1 done! thanks for your time on reading my question. – Martin Larizzate Nov 25 '19 at 13:11
  • 1
    can add aura if for testing to check parameter1 is exiting while loading childcmp ` <aura:if isTrue="{!not(empty(v.parameter1))}"> <c:CMP_ListigItems parameter1="{!v.parameter1}"/> </aura:if> ` – sdandamud1 Nov 25 '19 at 13:17
  • @sdandamud1 I just tested your Idea, but the issue persists. – Martin Larizzate Nov 25 '19 at 13:38
0

The issue was the event who builds RootCMP

I was building it using just an aura:if and solved it loading dynamically de RootComponent.

In the solution I replaced the aura:if with an attribute of type Component.

and it is being loaded with a function like this:

loadRootCMP: function(component) {
        $A.createComponent("c:RootCMP", 
        {
            "parameter1"  : component.get("v.parameter1"),
        }, 
        function(newCmp, status, errorMessage) {
            if (component.isValid()) {
                if(status == "ERROR") {
                    console.log('Creating Dynnamic component- Error Message--',errorMessage);
                }
                component.set("v.RootCMPContainer", newCmp);
            } 
        } );
  },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.