Hi, please help me, This code does not work for me?
import { Component, NgZone } from '@angular/core';
import { NavController, AlertController, Platform } from 'ionic-angular';
import { NFC, Ndef } from 'ionic-native';
@Component({
selector: 'page-scan',
templateUrl: 'scan.html'
})
export class ScanPage {
public tag:any;
constructor(public navCtrl: NavController, private Alert: AlertController, private zone: NgZone,private platform: Platform) {
this.tag = {};
}
ionViewWillEnter(){
this.platform.ready().then(() => {
this.cekNFC();
});
}
cekNFC() {
NFC.enabled()
.then(() => {
console.log("NFC is ready");
this.addListenNFC();
// IF Disabled
})
.catch(err => {
console.log(err);
let alert = this.Alert.create({
subTitle : "NFC DISABLED",
buttons: [{ text : "OK"},{ text : "Go Setting",
handler : () => {
NFC.showSettings();
}
}]
});
alert.present();
});
}
addListenNFC() {
console.log("Listening...");
NFC.addNdefListener(nfcEvent => this.sesReadNFC(nfcEvent.tag)); // <-- does not work for me
}
sesReadNFC(data):void {
this.tag = JSON.parse(JSON.stringify(data, null, 4));
console.log(JSON.stringify(data, null, 4));
}
}