How to get value from text box in Salesforce Lightning Component?

Sample Code:

Lightning Component:

<aura:component implements="forceCommunity:availableForAllPageTypes">
    <ui:inputText label="First Name" value="{!v.firstname}"/><
    <ui:button label="Register" press="{!c.registerUser}"/>
</aura:component>

Lightning Component Controller:

({
registerUser : function(component, event, helper) {
            alert(component.get("v.firstname"));
}
})

Cheers!!!

2 comments:

  1. When I run this code it is showing undefined.

    So, I have modified your code please let me know your feedback on this






    ({
    registerUser : function(component, event, helper) {
    alert(component.find("name").get("v.value"));

    }
    })

    ReplyDelete
    Replies
    1. Define the variables in the component to fix this undefined issue.

      Delete