3

Can someone explain me, why object binding is not working?

cmpOne.cmp

<aura:component extensible="true" abstract="true" access="global">
    <aura:attribute name="testObject" type="Account" access="global"/>

    <span>
        {!v.body}
    </span>
</aura:component>

cmpOneFirst.cmp

<aura:component extends="c:cmpOne" access="global">  
    <ui:inputText value="{!v.testObject.Name}" /> 
</aura:component>

cmpOneSecond.cmp

<aura:component extends="c:cmpOne" access="global">
    <aura:attribute name="types" type="Aura.Component[]" access="global"/>
    {!v.types}
</aura:component>

cmpOneThird.cmp

<aura:component extends="c:cmpOne" access="global">
    // value of field should be changed, as  this value  is changing  in  inner component
    {!v.testObject.Name} <br/> 

    <c:cmpOneSecond>
        <aura:set attribute="types">
            <c:cmpOneFirst testObject="{!v.testObject}"/>
        </aura:set>
    </c:cmpOneSecond>
</aura:component>

No controllers.

Desired behaviour: when you change value of name field in cmpOneFirst.cmp, new value is displayed in cmpOneThird.cmp

If you change type of testObject attribute from Account to String - binding works. Any suggestions?

4

I've had this happen before and was able to resolve it by using a default attribute to predefine the keys/values of the object fields that you want to bind on.

Try something like this:

<aura:attribute name="testObject" type="Account" 
                default="{ 'sobjectType':'Account', 'Name' : ''}"
                access="global"/>

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.