Reputation: 73
I wan't write app can call by number user input.
But i use http://ionicframework.com/docs/v2/native/callnumber/ it not working.
it my code ts
import { Component } from '@angular/core';
import {CallNumber} from 'ionic-native';
import { Platform, ActionSheetController } from 'ionic-angular';
// import { NavController } from 'ionic-angular';
declare var window;
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(
public platform: Platform,
public actionsheetCtrl: ActionSheetController
) { }
strShowInHtml = "";
callIT(){
// window.location = '12345';
CallNumber.callNumber("12345", true)
.then(() =>{
console.log('Launched dialer!');
this.strShowInHtml="ok";
})
.catch(() => {
console.log('Error launching dialer');
this.strShowInHtml="error";
});
}
}
and my code html:
<ion-header>
<ion-navbar>
<ion-title>Action Sheets</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding class="action-sheets-basic-page">
<button md-button (click)="callIT()">callIT</button>
</ion-content>
I know I can use
<a ion-button href="tel:+0839504890">Call me 1 </a>
but i don't want to use it, beaucase it will go to view Call Phone. I want to click button and my app Ionic 2 will call number user input.
Upvotes: 7
Views: 6004
Reputation: 133
<ion-fab left bottom>
<a href="tel:number" class="button" ion-fab color="light">
<ion-icon name="keypad"></ion-icon>
</a>
</ion-fab>
Use this cordova plugin
mx.ferreyra.callnumber 0.0.2 "Cordova Call Number Plugin"
Upvotes: 0
Reputation: 2888
Just do this to solve the issue:
Upvotes: 0
Reputation: 311
I used this way the other day. and worked :) I hope it works for you
import {CallNumber} from '@ionic-native/call-number';
constructor(public navCtrl: NavController, public navParams:
NavParams,public call:CallNumber){}
async callNumber():Promise<any>{
try{
await this.call.callNumber("+XXXXXXXXX",true);
}
catch(e){
console.log(e);
}
}
Upvotes: 0
Reputation: 53
You're import isn't complete. The documentation states to install the call-number plugin:
$ ionic plugin add --save call-number
$ npm install --save @ionic-native/call-number
And then reference the plugin:
import { CallNumber } from '@ionic-native/call-number';
Upvotes: 0
Reputation: 383
In your Component class please write as below
callIT(mobNumber:string)
{
window.open("tel:" + mobNumber);
}
Upvotes: 7