3

I'm building a generic lookup component in lightning. I'd like to be able to pass custom templates into this component. Can this be done as an attribute?

Here's the relevant component and what I tried now.

<aura:component controller="lightningUtils">
<aura:attribute type="List" name="filteredResults" />
<aura:attribute type="String" name="template" default="templateLookupDefault"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>


<div class="slds-form-element">
    <ui:inputText aura:id="quickLookupInput" class="slds-input" value="{!v.search}" updateOn="keyup" keyup="{!c.filterList}" placeholder="Search" />
</div>

<c:{!v.template} filteredResults="{!v.filteredResults}"/>

4

It looks like you're trying to reference a component dynamically? If that's the case, you could create a component and insert it into the markup through your controller. Here's an example:

// markup
<div aura:id='divToSet'>

</div>

// controller
$A.createComponent('c:COMPONENT_NAME_HERE',
    {
        'filteredResults': someValueHere
    },
    function(newComp){
        component.find('divToSet').set('v.body', newComp);
    }
);

I have not hit any snags using this method in the past. Hope this helps!

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.