0

I am new to Lightning Aura component and created a simple component to add 2 numbers. However while saving I am getting this error:

Failed to save Add2Numbers_C.cmp: ParseError at [row,col]:[4,50] Message: Element type "aura:attribute" must be followed by either attribute specifications, ">" or "/>".: Source

below is my component code:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="Number1" type = "Integer" default="39"/>
    <aura:attribute name="Number2" type="Integer"default="2"/>
    <aura:attribute name="sum" type="Integer"/>
    {!v.Number1}+{!v.Number2}={!v.sum}
    <br/><br/>
    <ui:button name="Add" press="{!c.add}"/>
    
</aura:component>

below is the code for the js cotroller file:

({
add : function(component) {
    var add2=component.get("v.Number1")+component.get("v.Number2");
    component.set("v.sum",add2);
}

can some one please help me to understand what is going wrong here?

1 Answer 1

1

Few issues in your component.

<aura:attribute name="Number2" type="Integer"default="2"/>

no space before default.

Second issue is ui namespace are being deprecated. Documentation

Final Component.

<aura:component description="sumComponennt" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">

    <aura:attribute name="Number1" type = "Integer" default="39"/>
    <aura:attribute name="Number2" type="Integer" default="2"/>
    <aura:attribute name="sum" type="Integer"/>

    <div class="slds-color__background_gray-1">
        {!v.Number1}+{!v.Number2}={!v.sum}
    </div>
    <br/><br/>
    <lightning:button name="Add" label="Add" onclick="{!c.add}"/>
</aura:component>

JS :

({
    add: function (component) {
        var add2 = component.get("v.Number1") + component.get("v.Number2");
        component.set("v.sum", add2);
    }
})

Result:

enter image description here

1
  • My previous code worked with the same piece of codes/same codes not sure why it was giving error earlier. However thanks for the answer and I will later on check the solution provided by you as well. Commented Jan 3, 2023 at 15:41

You must log in to answer this question.

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