What are the steps to initiating a phone call using Nativescript?

When I click the button, I want to initiate a phone call dialing the number displayed on the label. Here is my custom button:

<ActionBar>
    <NavigationButton (tap)="onBackTap()" android.systemIcon="ic_menu_back"></NavigationButton>
    <Label class="action-bar-title" style="font-family: Georgia, 'Times New Roman', Times, serif;
    font-size: 10px;" [text]="item.name"></Label>
</ActionBar>

<StackLayout>
<Label class="action-bar-title" style="font-family: Georgia, 'Times New Roman', Times, serif;
        font-size: 10px;" [text]="item.number"></Label>
    <Button text="&#xff17b; Call!" (tap)="onTap()" class="my-button"></Button>
</StackLayout>

This is the method onTap() in my component:

export class ItemDetailComponent implements OnInit {
    item: IDataItem;

    constructor(
        private _data: DataService,
        private _route: ActivatedRoute,
        private _routerExtensions: RouterExtensions
    ) { }

    ngOnInit(): void {
        const id = +this._route.snapshot.params.id;
        this.item = this._data.getItem(id);
    }

    onBackTap(): void {
        this._routerExtensions.back();
    }
    onTap(): void {
       // Code to make a phone call goes here
    }
}

Any suggestions on how to implement the functionality of making a phone call?

Answer №1

If you want to incorporate phone functionality into your NativeScript app, consider using the plugin NativeScript Phone.

There are two main options available:

  1. You can make a call directly from within the application, but this requires permission for CALL_PHONE.

  2. Alternatively, you can open the default phone call app with the number pre-entered.

In my view, the second option is preferable as it eliminates the need for additional permissions.

To implement TNSPhone:

import * as TNSPhone from 'nativescript-phone';

Then, use the dial method within your onTap function:

TNSPhone.dial(123456789, true);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Showcase pictures within an angular smart table

Is it possible to display images in a column within an ng smart table? We have several columns consisting mostly of data, with one column dedicated to displaying images. Following the ng smart table concept, I attempted to implement the code below which cu ...

Can one inherit under specific conditions?

I have just started exploring the OOP paradigm and I am curious to know if it is possible to have conditional inheritance in TypeScript. This would help avoid repeating code. Here is what I have in mind. Any suggestions or recommendations are greatly appre ...

Maintaining checked items in their original state while searching for another one in ion-searchbar can be achieved by properly handling

My goal is to maintain the checked items as checked when searching for another item in ion-searchbar. While I have managed to keep the checked items, the checkmark icon does not stay checked. What I aim for is to retain the checked state of all food items ...

Exploring JSON data in Angular 7 by leveraging services

I am working on a node server which is returning the following JSON data: { "ResponseStatus": { "ResponseCode": 0, "ResponseMessage": "Success." }, "Events": [ { "CodEspec": 65957, ...

Troubleshooting the display of API-generated lists in Angular 8

I am encountering an issue in Angular 8 when trying to display my list on a page. Below is the code from my proposal-component.ts file: import { Component, OnInit, Input } from "@angular/core"; import { ActivatedRoute, Params } from "@angular/router"; imp ...

Is there a workaround for the React useContext issue in Typescript aside from using <Partial>?

I am currently working on a React app that utilizes the useContext hook, but I am facing challenges with correctly typing my context. Here is the code snippet in question: import React, { useState, createContext } from 'react'; import endpoints f ...

Misunderstanding between Typescript and ElasticSearch Node Client

Working with: NodeJS v16.16.0 "@elastic/elasticsearch": "8.7.0", I am tasked with creating a function that can handle various bulk operations in NodeJS using Elasticsearch. The main objective is to ensure that the input for this funct ...

Testing an Angular2 service that employs RxJs subjects through unit testing

Within my application, I developed an AuthService to manage backend service authorization. Utilizing a BehaviorSubject that updates its subscribers, components are notified of new login states. Below is the simplified code snippet: @Injectable() export cl ...

Acquiring the handle of ngComponentOutlet

I am dynamically creating a component using ngComponentOutlet. Here is an example: import {Component, NgModule} from '@angular/core' import {BrowserModule} from '@angular/platform-browser' @Component({ selector: 'alert-success& ...

Issue encountered with Typescript and Request-Promise: Attempting to call a type that does not have a call signature available

I have a server endpoint where I want to handle the result of an asynchronous request or a promise rejection by using Promise.reject('error message'). However, when I include Promise.reject in the function instead of just returning the async requ ...

Configuring the CKEditor edit functionality in Angular 2

If you're looking to configure your CKEditor in Angular2, you can refer to the documentation provided by CKEditor here. Here is an example of how I am using it in my HTML: <ckeditor [(ngModel)]="ckeditorContent" [config]="{toolbar : 'Bas ...

"Excel file becomes inaccessible after being downloaded from server using Lambda function with Node.js and Angular

My Nodejs code generates an excel file, which is then transformed based on client request. I am sending a request from an Angular frontend. The code utilizes exceljs to create the excel file. let [row] = await conn.execute( "Query& ...

Unfinished tags pairing with Angular HTML bindings

I am attempting to display HTML code. I have two separate pieces of code - one for the header and the other for the footer. My challenge is that the header contains unclosed tags, which are closed in the footer. When I try to bind with [innerHTML], Angular ...

Guide to connecting data from the backend to the frontend in the select option feature using Angular 9

I have a backend system where I store a number representing a selected object, which I am trying to display in a select option using Angular. Currently, the select option only displays a list of items that I have predefined in my TypeScript code using enu ...

Difficulty accessing class functions from the test application in Node.js NPM and Typescript

I created an NPM package to easily reuse a class. The package installs correctly and I can load the class, but unfortunately I am unable to access functions within the class. My project is built using TypeScript which compiles into a JavaScript class: For ...

Using a Typescript variable prior to its assignment

I encountered an issue in my Typescript / ReactJS project displaying the error message Variable 'myVar' is used before being assigned. TS2454 This problem arises with my TS version 4.2.3, appearing both in my IDE and during code execution. Inte ...

Retrieve a collection of Firestore documents based on an array of unique identifiers

I have a Firestore collection where one of the values is an array of document IDs. My goal is to retrieve all items in the collection as well as all documents stored within the array of IDs. Here is the structure of my collection: This is my code: export ...

Is it possible to transfer files using Angular 2?

Currently, I am utilizing Angular2 and TypeScript to transmit a file in conjunction with JSON Data to a designated server. HTML Code <input type="file" class="form-control" name="avatar" id="uploadyour" name="uploadyour" #uploadyour="ngModel" [(ngMode ...

Tips for incorporating IntersectionObserver into an Angular mat-table to enable lazy loading功能?

I am looking to implement lazy loading of more data as the user scrolls down the table using IntersectionObserver. The container I am using is based on the Bootstrap grid system. However, despite using the code below, the callback function is not being tri ...

Set every attribute inside a Typescript interface as non-mandatory

I have defined an interface within my software: interface Asset { id: string; internal_id: string; usage: number; } This interface is a component of another interface named Post: interface Post { asset: Asset; } In addition, there is an interfa ...