Components are the building blocks of an app. They can be wired up to a model to load your data. The component you create in this step provides a form that takes in user input about an expense, such as expense amount and date.
Click File > New > Aura Component.
Enter form for the Name field in the New Aura Bundle popup window. This creates a new Aura component, form.cmp.
In the source code editor, enter this code.
Code Highlights
<ui:button class="btn" label="Submit" press="{!c.newExpense}"/> Aura components provide a rich set of attributes and browser event support. For example, the press event in ui:button enables you to wire up an action (c.newExpense) when the button is pressed.
The c. in {!c.newExpense} represents the client-side JavScript controller action that runs when the Submit button is clicked, which creates a new expense.
The attributes and expressions here will become clearer as you build the app. For example, {!v.exp} evaluates the number of expenses in the model and {!v.total} evaluates the total amount.
Add Styles
Click STYLE in the sidebar to create a new resource named form.css. Enter these CSS rule sets.
Add To expenseTracker.app
Add the component to the app. In expenseTracker.app, add the new component to the markup. Replace namespace with the name of your registered namespace.
Test The App
Save your changes and click Update Preview in the sidebar to preview your app. Alternatively, reload your browser.
Note: In this step, the component you created doesn’t display any data since you haven’t created the model yet. You created a component that provides an input form and view of your expenses. Next, you’ll set up the model to load expense data in the component, which uses <aura:iteration> to iterate through a list of items provided by the model using the expression {!m.expenses}.