How to make a contact's phone number clickable

2019-06-24 02:00发布

I cloned the ionic project from GitHub

While the contact's phone number is not clickable to call and message. So for the index.html file line 39, I converted from

<p ng-if="contact.emails.length > 0">{{contact.emails[0].type}} : {{contact.emails[0].value}}</p>

to

<p ng-if="contact.phones.length > 0">{{contact.phones[0].type}} : <a ng-href='{{contact.phones[0].value}}'>{{contact.phones[0].value}}</a></p>

But it turns out the app will not load any contact's information anymore.

Is there anything I missed or am I totally wrong on sending data?

2条回答
beautiful°
2楼-- · 2019-06-24 02:40

to make phone call with ionic you need to add this code in confi.xml

<access launch-external="yes" origin="tel:*" />

and in your view you need to add:

<a ng-href=tel:{{user.phoneNumber}} class="button button-positive">Call me</a>
查看更多
太酷不给撩
3楼-- · 2019-06-24 02:43

Update:

I've just noticed it's (probably) an issue with loading data not the link itself. Would need to see your controller code to know more about why it's not populating the ng-href if it's not the issue below...

Previously:

Using the following href should be enough to trigger a call:

tel:' + number

Angular (which ionic sits on) doesn't like anything unusual going into an anchors href unless you tell it you want it to. See here:

http://forum.ionicframework.com/t/ng-href-tel-redirecting-to-call-with-empty-number/4567/2

The quickest fix, if you 'just' want it to work is this in your view:

<p ng-if="contact.phones.length > 0">{{contact.phones[0].type}} : <a href="#" ng-click="triggerCall('{{contact.phones[0].value}}')">{{contact.phones[0].value}}</a></p>

and then in your controller:

$scope.triggerCall = function(number){
    document.location.href = 'tel:' + number
}
查看更多
登录 后发表回答