Sunday, 11 June 2017

how to call class without declaring it in constructor angular 2

I am trying to use NFC module of Ionic 2. This is my code:

nfc-scan.ts:

    import {Component} from '@angular/core';
    import {IonicPage, NavController, NavParams, Platform} from 'ionic-angular';
    import { Device } from '@ionic-native/device';
    import {NFC, Ndef} from '@ionic-native/nfc';

    @IonicPage()
    @Component({
        selector: 'nfc-scan',
        templateUrl: 'nfc-scan.html',
    })
    export class NfcScan {
        @ViewChild(Nav) nav: Nav;
NFC: NFC;

    constructor(public platform: Platform,
                    public navCtrl: NavController,
                    public navParams: NavParams,
        ) {

        }

    // NFC Scanning
        checkNFC()
        {
            this.NFC.enabled()
                .then(() => {
                    this.addListenNFC();
                })
                .catch(err => {
                    console.log(err);
                });
        }
    }

nfs-scan.html

<ion-content padding>
    <button on (click)="checkNFC()">Scan NFC</button>
</ion-content>

When I run the application, I get the error:

Property 'enabled' does not exist on type 'typeof NFC'.

I know I am not declaring NFC in the constructor of nfc-scan.ts. But when I do so, the page won't even load altogether.



via PHPDev

No comments:

Post a Comment