4

I have declared an auro Map attribute in my Lightning Component but when i try to set key value pair to the Map in CLient-Side Controller it throws null error.

COMPONENT CODE :

 <aura:component implements="flexipage:availableForAllPageTypes>    
   <aura:attribute name="FilesNameMap" type="Map"/>
 </aura:component>

CLIENT_SIDE CONTROLLER CODE :

 onChangeFunction : function(component,event){

   var FilesNameMap = component.get("v.FilesNameMap");
       FilesNameMap['city']='bangalore';

}

Please suggest on how to use Map attribute.

7

UPDATE

I believe this is a bug. If you do not default your Map to empty object default="{}", then lightning appears to not register the existence of the Map declared in the markup.

So, the fix is simple - change your attribute definition to this:

<aura:attribute name="FilesNameMap" type="Map" default="{}"/>

PREVIOUS

You have a typo. In your attribute definition, you have called the Map FilesNameMap but in your getter you have called it FilesObjectMap.

Which means it's going to be null when you try to set something to it.

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.