1

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}"/>
    {!v.basicInfo}
    <ui:button press="{!c.setChildAttribute}">Pass Attribute</ui:button>
</aura:component >

And its controller:

({
    init: function(cmp){
        console.log('cmp -> ' + cmp);
        $A.createComponent(
            "c:SegmentBasicInfo",
            {
                "name" : "testName",
                "message" : "test message"
             },
            function(basicInfo){
                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?

1

1 Answer 1

1

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");
}
2
  • 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! Commented Jun 16, 2016 at 16:24
  • Oops you're right! I keep forgetting about that pesky v :)
    – Charles T
    Commented Jun 16, 2016 at 17:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .