0
イオンで空白のページにqrスキャナを実装しようとしていますが、予期しないトークンを最初に 'これ'にエラーが表示されたら、最後の中括弧または期待される陳述書。このページでionic qrscannerを実行する問題
私は非常にイオンとタイスクリプトに新しいので、少し苦労しています。これは、ネイティブのqrscannerのためのイオン文書から直接取ったものです。私も他の人とは異なるコードを試しましたが、一般的には「this」でエラーが発生します
以下はそのページに関連するコードの全体です。また、問題の場合にはngmodulesにプラグインを追加しました。あなたがこの方法でそのコードセクションを同封していないためだ
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner';
@IonicPage()
@Component({
selector: 'page-qrcode',
templateUrl: 'qrcode.html',
})
export class QrcodePage {
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private qrScanner: QRScanner){}
ionViewDidLoad() {
console.log('ionViewDidLoad QrcodePage');
}
this.qrScanner.prepare()
.then((status: QRScannerStatus) => {
if (status.authorized) {
// camera permission was granted
// start scanning
let scanSub = this.qrScanner.scan().subscribe((text: string) => {
console.log('Scanned something', text);
this.qrScanner.hide(); // hide camera preview
scanSub.unsubscribe(); // stop scanning
});
// show camera preview
this.qrScanner.show();
// wait for user to scan something, then the observable callback will be called
} else if (status.denied) {
// camera permission was permanently denied
// you must use QRScanner.openSettings() method to guide the user to the settings page
// then they can grant the permission from there
} else {
// permission was denied, but not permanently. You can ask for permission again at a later time.
}
})
.catch((e: any) => console.log('Error is', e));
}
大変ありがとうございました。私は学校でcやC++を学んでいたのに、自分でプロジェクトをやろうとしていたので、このコードの分野には本当に新しいです。だから、それらのドキュメントでは、あなた自身の機能をそれらすべてに割り当てる必要がありますか? – ParaDucks
クラス内に配置するコードはすべて、メソッド内またはプロパティの右側に配置する必要があります。 – Fenton