ionic2 扫码 (条形码、二维码)

先安装插件
ionic cordova plugin add phonegap-plugin-barcodescanner
npm install --save @ionic-native/barcode-scanner
然后在app.module.ts内引入,
import {BondedDevicePage} from '../pages/bonded-device/bonded-device';
@NgModule({
providers: [
BarcodeScanner
]
})
在页面调用
import { BarcodeScanner } from '@ionic-native/barcode-scanner';

constructor(private barcodeScanner: BarcodeScanner) { }

...

getCode(){
this.barcodeScanner.scan().then((barcodeData) => {
// Success! Barcode data is here
}, (err) => {
// An error occurred
});
}
条形码打印为


image.png

二维码看内置信息喽~

你可能感兴趣的:(ionic2 扫码 (条形码、二维码))