I am getting array of string from component's attribute to lightning controller, now I want to split that string to comma separated values and want to assign that to another component variable but split function is not working in js controller, the below error I am getting:
Action failed: c:ContactCardInfo$controller$doInit [Cannot read property 'split' of undefined]`
controller.js
({
doInit: function(component, event, helper) {
console.log('FieldApiNames '+component.get('v.FieldApiName'));
var fieldString = component.get('v.FieldApiName');
var array = [];
array = fieldString.split(',');
component.set('v.conFields', array);
helper.getContactRecordId(component);
}
})
Component:
<aura:component implements="force:appHostable,force:hasSObjectName,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="ContactInfoController">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="contactLookup" type="string"/>
<aura:attribute name="HeaderLabel" type="string"/>
<aura:attribute name="FieldApiName" type="string"/>
<aura:attribute name="contactRecordId" type="id" />
<aura:attribute name="recordId" type="String"/>
<aura:attribute name="sobjecttype" type="String" default="{!v.sObjectName}"/>
<aura:attribute name="conFields" type="string[]"/>
<aura:attribute name="HeaderTitle" type="Aura.Component[]">
<h2>
<b>{!v.HeaderLabel}</b>
</h2>
</aura:attribute>
<lightning:card iconName="standard:contact" title="{!v.HeaderTitle}" />
<lightning:recordForm aura:id="recordViewForm"
objectApiName="Contact"
columns="2"
recordId="{!v.contactRecordId}"
fields= "{!v.conFields}"
mode="View" />
Design
<design:component label="Contact Object Configuration">
<design:attribute name="HeaderLabel" label="Header Label" />
<design:attribute name="contactLookup" label="Contact Field API Name" description="API Name of the Contact Object"/>
<design:attribute name="FieldApiName" label="Field API Name" />
FieldApiName
attribute? can you provide component markup as wellFieldApiName
attribute is?