离子打字稿错误

问题描述 投票:0回答:2

我是Ionic框架的新手。我正在尝试如何在应用程序中集成指纹授权。

为此,我在我的home.ts文件中添加了以下代码:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

import { FingerprintAIO } from '@ionic-native/fingerprint-aio';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, private fingerPrint: FingerprintAIO) {

  }

  this.fingerPrint.show({
    clientId: 'Fingerprint-Demo',
    clientSecret: 'password', //Only necessary for Android
    disableBackup:true,  //Only for Android(optional)
    localizedFallbackTitle: 'Use Pin', //Only for iOS
    localizedReason: 'Please authenticate' //Only for iOS
  })
  .then((result: any) => console.log(result))
  .catch((error: any) => console.log(error));
}

当我使用ionic cordova build android进行Android构建时,我收到以下错误:

typescript: src/pages/home/home.ts, line: 16 
            Unexpected token. A constructor, method, accessor, or property was expected. 

      L16:    this.fingerPrint.show({
      L17:      clientId: 'Fingerprint-Demo',

[15:24:38]  typescript: src/pages/home/home.ts, line: 25 
            Declaration or statement expected. 

      L24:    .catch((error: any) => console.log(error));

Error: Failed to transpile program

我该如何解决这个问题?

javascript typescript ionic-framework ionic2
2个回答
0
投票

将此代码放在constructor()中,就像这样,

constructor(public navCtrl: NavController, private fingerPrint: FingerprintAIO) {
      this.fingerPrint.show({
        clientId: 'Fingerprint-Demo',
        clientSecret: 'password', //Only necessary for Android
        disableBackup:true,  //Only for Android(optional)
        localizedFallbackTitle: 'Use Pin', //Only for iOS
        localizedReason: 'Please authenticate' //Only for iOS
      })
      .then((result: any) => console.log(result))
      .catch((error: any) => console.log(error));
}

0
投票
constructor(public navCtrl: NavController, private fingerPrint: FingerprintAIO) {
this.initFigerprint();
  }


initFigerprint(){

  this.fingerPrint.show({
    clientId: 'Fingerprint-Demo',
    clientSecret: 'password', //Only necessary for Android
    disableBackup:true,  //Only for Android(optional)
    localizedFallbackTitle: 'Use Pin', //Only for iOS
    localizedReason: 'Please authenticate' //Only for iOS
  })
  .then((result: any) => console.log(result))
  .catch((error: any) => console.log(error));
}
© www.soinside.com 2019 - 2024. All rights reserved.