Reputation: 103
I am following trying to set up a barcode scanner using the following - https://ionicframework.com/docs/native/barcode-scanner/
This is my code -
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(private barcodeScanner: BarcodeScanner) {
}
this.barcodeScanner.scan().then((barcodeData) => {
console.log(barcodeData);
}, (err) => {
});
}
When I run it, I get an error saying
Typescript Error
Unexpected token. A constructor, method, accessor, or property was expected.
I am not sure what is causing this error, as I have followed the code given.
Upvotes: 2
Views: 354
Reputation: 222582
You need to place the code inside a constructor or a function.
ScanCode() : any{
this.barcodeScanner.scan().then((barcodeData) => {
console.log(barcodeData);
}, (err) => {
});
}
Upvotes: 1