A Button component provides an easy-to-use way for interacting through the application and invoking custom logic in response to that. Once the user taps it, the button performs any actions attached to it.

API Reference for the Button Class

Native Component

Android iOS
android.widget.Button UIButton


Tap Event

A button component can attach to custom logic with its tap event. Handling the event is as easy as using (tap) in HTML, and implementing a tap handler in your component.

Attaching to the tap event handler from HTML:

<Button class="btn btn-primary btn-active" id="button" text="Tap me!" (tap)="onTap($event)"></Button>

Implementing the tap event handler in a component:

onTap(args: EventData) {
    let button = <Button>args.object;

    alert("Tapped " + this.counter + " times!");

Improve this document

Demo Source

Is this article helpful? Yes / No
Thank you for your feedback!

Tell us how we can improve this article

NativeScript is licensed under the Apache 2.0 license .
© Progress Software Corporation. All Rights Reserved.