离子打字稿错误

Ionic typescript error

我是 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

我该如何解决这个问题?

像这样把这段代码放在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));
}
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));
}