2016-11-11 61 views
5

我想写的应用程序可以通过号码用户输入呼叫。我可以用http://ionicframework.com/docs/v2/native/callnumber/不行。离子2电话号码不能正常工作

是我的代码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"; 
    }); 
    } 
} 

和我的代码的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> 

我知道我可以使用

<a ion-button href="tel:+0839504890">Call me 1 </a> 

,但我不希望使用它,beaucase它会去查看呼叫电话。 我想点击按钮,我的应用程序Ionic 2会拨打用户号码输入。

回答

6

在你的组件类,请填写下面

callIT(mobNumber:string)  
{ 
     window.open("tel:" + mobNumber); 
} 
0

你导入是不完整的。该文档的状态来安装呼叫号码插件:

$ ionic plugin add --save call-number 
$ npm install --save @ionic-native/call-number 

,然后引用插件:

import { CallNumber } from '@ionic-native/call-number'; 
+0

此插件https://github.com/Rohfosho/CordovaCallNumberPlugin无法正常工作 –

0

我用了一天这样。并努力:)我希望它为你工作

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); 
} 
} 
0
<ion-fab left bottom> 
     <a href="tel:number" class="button" ion-fab color="light"> 
      <ion-icon name="keypad"></ion-icon> 
     </a> 
    </ion-fab> 

使用此插件科尔多瓦

mx.ferreyra.callnumber 0.0.2 "Cordova Call Number Plugin"