Say I have a Component that acts as a container and on init I dynamically create a custom component. The custom component has 2 attributes, "name" and "message".

Container Component:

<!-- Container Component -->
<aura:component >
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <ui:button press="{!c.setChildAttribute}">Pass Attribute</ui:button>
</aura:component >

And its controller:

    init: function(cmp){
        console.log('cmp -> ' + cmp);
                "name" : "testName",
                "message" : "test message"
                cmp.set("v.basicInfo", basicInfo);
    setChildAttribute : function (cmp){
        var basicInfo = cmp.get("v.basicInfo");
        basicInfo.name = "newTest";
        basicInfo.message = "new Test Message";
        cmp.set('v.basicInfo', basicInfo);

Inner Component:

<!-- Inner Component -->
<aura:component >
    <aura:attribute name="name" type="String"/>
    <aura:attribute name="message" type="String"/>
    {!v.name} says {!v.message}!
<aura:component >

The dynamic component is successfully created but the button doesn't update the attributes.

What am I missing?


I don't think you can set component attributes with dot notation like that. Assuming v.basicInfo is of type Aura.Component, try instead:

setChildAttribute : function (cmp){
    var basicInfo = cmp.get("v.basicInfo");
    basicInfo.set("v.name", "newTest");
    basicInfo.set("v.message", "new Test Message");
  • nice! One small change: basicInfo.set("v.name", "newTest"); and it works! if you'll update your response i'll mark it as correct. Thanks! Jun 16 '16 at 16:24
  • Oops you're right! I keep forgetting about that pesky v :)
    – Charles T
    Jun 16 '16 at 17:07

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.