Activity Forums Salesforce® Discussions What is difference between the use of {#var.attribute} and {!var.attribute} in Salesforce?

  • sushant

    Member
    February 7, 2017 at 10:25 am

    Hi Mohit,

    f you want to show a value dynamically based on a aura:attribute, generally we tend to use: {!v.attrib}

    Eg: <ui:button label="{!v.attrib}" />

    So if you do cmp.set('v.attrib','test'), then aura:framework automagically does an dirty checking and changes the value accordingly.(Two-way binding)

    So the label of the <ui:button> is set to test, just think of this as special expression that directly point to the live reference of the attribute in the component(JS perspective), which is quiet similar to{{v.attrib}} expression in Angularjs which eventually does the same thing.

    What if you want to show a value dynamically based on a aura:attribute but it needs to work only once,when it is rendered in the view initially.

    So you should go with : {#v.attrib} expression, which might improve the performance if there large no.of such expression(where you don't need such bindings), because it won't be taken into account during dirty checking.AngularJS also has the same one-way binding stuff in its armour :{{::v.attrib}}

    For example:

    <aura:component>
    <aura:attribute name="test" type="String" default="world"/>
    hello {#v.test} // print hello world and does not change
    hello {!v.test} // prints hello world and 'test' changes based on input value
    <ui:inputText value="{!v.test}"/>
    </aura:component>

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos