Display Telephone Number as link to dial number


#1

How do I display a telephone number so that a user can click the number it dial.

I have previously used an href=“tel:”.

How to do this is Nativescript.


#2

It’s not anchor tag / html where you could expect it to work as it would in browser. You will have to decorate a button / label to look like a link using CSS and on tap use nativescript-phone plugin to initiate the call action.


#3

Getting error in Playground on iOS Could not find module nativescript-phone.

I’ve added the NPM package to my project on play.nativescript.org and have defined the following:-

var phone = require(“nativescript-phone”);

Preview crashes when trying to load the module, does this mean it will not work in preview and will have to compile in Sidekick to test.


#4

Not all the plugins are compatible with Playground, sometimes plugin may need relative import path. Besides nativescript-phone plugin requires permissions need to be declared during build time, so it may not work well at Playground.


#5

I got this working by using nativescript HtmlView tag :

<HtmlView html="here's my number so you can call it : ++yy (0)xxxxxxxxx"></HtmlView>

I was able to click the number and it redirected my to phone app so I can call, message or add contact on android.
I don’t know what phone formats are supported though, but it seems pretty wide


#6

That uses auto link feature in Android, something similar is available in iOS too. But the reason for choosing nativescript-phone plugin is to acquire necessary permissions and make sure it works on all platforms and OS versions.

Also HtmlView internally uses nothing but Label and it doesn’t recognize all your html tags.


#7

Yes good points, I agree HtmlView is a bit messy as it doesn’t recognize all html tags and auto-link feature recognizes some links that aren’t.
The plugin is the way to go for a well implemented feature, I just wanted to point out that quick solution :slight_smile: