angularjs - ionic2 phone call function show error: Unexpected token. A constructor, method, accessor, or property was expected -


about.html here html page

<ion-content>         <ion-fab center buttom>       <button ion-fab color="light">         <ion-icon name='call'></ion-icon>       </button>     </ion-fab>      <!-- <a ion-button color="light" href="tel:1800889958">     立即拨打     </a>   -->    </ion-content> 

about.ts

here typescript page. install call number plugin ald, and import app.module.ts also.

error showing @ 'this'

error message: unexpected token. constructor, method , accessor, or property expected.

import { component } '@angular/core'; import { callnumber } '@ionic-native/call-number';   @component({   selector: 'page-about',   templateurl: 'about.html' })  export class aboutpage {    constructor(private call: callnumber) { }    this.callnumber.callnumber("1800889958", true)   .then(() => console.log('launched dialer!'))   .catch(() => console.log('error launching dialer'));  } 

cli error show:

[09:56:04]  typescript: src/pages/about/about.ts, line: 14              unexpected token. constructor, method, accessor, or property expected.         l14:    this.callnumber.callnumber("1800889958", true)       l15:    .then(() => console.log('launched dialer!'))  [09:56:04]  typescript: src/pages/about/about.ts, line: 18              declaration or statement expected.  

you must add callnumber provider.

import { callnumber } '@ionic-native/call-number';  ...  @ngmodule({   ...    providers: [     ...     callnumber     ...   ]   ... }) export class appmodule { } 

and about.ts should this:

import { component } '@angular/core'; import { platform } 'ionic-angular'; import { callnumber } '@ionic-native/call-number';   @component({   selector: 'page-about',   templateurl: 'about.html' })  export class aboutpage {    constructor(private call: callnumber, private platform: platform) {       this.platform.ready().then(() => {         this.calltonumber();      });   }    private calltonumber() {      this.call.callnumber("1800889958", true)          .then(() => console.log('launched dialer!'))          .catch(() => console.log('error launching dialer'));     }    } 

check line this.call.callnumber, had this.callnumber.callnumber , seems issue.

update:

always wait platform.ready() promise when want use native functionallities, because if try native apis before fail.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -