Ionli 2 shtrix Brauzer

Ionic2 yordamida shtrix kodli skanerdan foydalanib android mobilini skanerlashni xohlayman. Men ionning yangi o'quvchisiman. Men kodni sinab ko'rdim,

home.ts

  import { Component } from '@angular/core';

  import { NavController } from 'ionic-angular';
  declare var cordova:any;
  @Component({
  selector: 'page-home',
  templateUrl: 'home.html'
  })
  export class HomePage {

  constructor(public navCtrl: NavController) {

  }

  scan() {
  var me = this;
  if (cordova.plugins.barcodeScanner) {
    cordova.plugins.barcodeScanner.scan((imageData) => {
        alert(imageData.text);

    }, (error) => {
        alert("An error happened -> " + error);         
    });
  }

  }
  }

home.html

  
  
    Home
  
  

 
 <button primary (click)="scan()">Scan</button>
 

Lekin men xatoga yo'l qo'ydim: "Cordova" o'zgarmaydigan topilmadi.

Ushbu plaginni ishlatdim -

https://ionicframework.com/docs/v2/native/barcode-scanner/

ionli 2 shtrix-skaner uchun

Javobingiz uchun rahmat.

0
Ko'rsatilgan o'zgarishlarni amalga oshirganingizdan keyin ham xatoga yo'l qo'yasizmi? Buyruqning irodasini "ionic build android" ni yozib, ilovani yarating. Keyin apk faylini telefoningizga ishga tushiring. Ushbu xatolikni brauzerda olish normaldir.
qo'shib qo'ydi muallif alpmirza, manba

7 javoblar

Avval loyihangizni import qiling:

$ ionic cordova plugin add phonegap-plugin-barcodescanner
$ npm install --save @ionic-native/barcode-scanner

Komponent fayllari:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers: [ BarcodeScanner ]
})
export class HomePage {

  constructor(
    private barcodeScanner: BarcodeScanner,
    public navCtrl: NavController) {

  }

  scan() {
   this.barcodeScanner.scan().then((barcodeData) => {
        console.log(JSON.stringify(barcodeData))
      }, (err) => {
       //error
      });
  }

}
1
qo'shib qo'ydi

1.

$ cordova plaginini telefon plagini-plugin-barcodescanner-ni qo'shing

$ npm install --save @ ionic-native/shtrix-skaner

2.

app.module.ts

import { BarcodeScanner } from '@ionic-native/barcode-scanner';
   @NgModule({

   ......

   providers: [
     BarcodeScanner,
     {provide: ErrorHandler, useClass: IonicErrorHandler}
   ]
 })
 export class AppModule {}

skaner.ts

 import { Component } from '@angular/core';
 import { NavParams, NavController } from 'ionic-angular';
 import { BarcodeScanner } from '@ionic-native/barcode-scanner';

 @Component({
    selector: 'page-contact',
    templateUrl: 'contact.html'
 })
export class ContactPage {
    constructor( public nacCtrl: NavController,
    public NavParams: NavParams,
    private barcodeScanner: BarcodeScanner) { }

  takeScan(){
      this.barcodeScanner.scan().then((barcodeData) => {
     //Success! Barcode data is here
      alert(barcodeData.text);
      console.log("Barcode Format -> " + barcodeData.format);
      console.log("Cancelled -> " + barcodeData.cancelled);

   }, (err) => {
     //An error occurred
     console.log("An error happened -> " + err);
   });
 }

}
1
qo'shib qo'ydi
How to create perfect Barcode/QR Scanner. let's do it.

Birinchidan, o'rnatish

  1. ionic cordova plaginini telefon plagini-plugin-barcodescanner qo'shing
  2. npm install --save @ ionic-native/shtrix-skaner
  3. @ ion-native/core -save
  4. ni o'rnating
  5. cordova platforma yangilanishi android

all are done..import BarcodeScanner in app.module.ts .like this
import { BarcodeScanner } from '@ionic-native/barcode-scanner';

provayderlar: [     BarcodeScanner   ]

after that, we must declare in typescript file which you'll use
import { BarcodeScanner } from '@ionic-native/barcode-scanner';

scan(){
      this.barcodeScanner.scan().then((barcodeData) => {
        console.log(JSON.stringify(barcodeData))  
      }, (err) => {  
       //error 
      });
    }

in this case. you can face like this errors,
ERR_FILE_NOT_FOUND (file:///android_asset/www/index.html): or
*Unexpected token ) in main.ts *
don't worry about it..remove android/ios plugin from command prompt. and install it.
cordova platform update android

I hope good new. spy

0
qo'shib qo'ydi

Hujjatlardagi kabi, ionli 2 shtrix-skanerdan foydalanish uchun buni qilish kerak

import { BarcodeScanner } from 'ionic-native';

BarcodeScanner.scan().then((barcodeData) => {
   //Success! Barcode data is here
  }, (err) => {
  //An error occurred
});

O'rnatishdan so'ng, uni ionic-native dan ko'chirib olishingiz va uni funksiyalaridan foydalanish uchun uni chaqirishingiz kerak.

Umid qilamanki: D

0
qo'shib qo'ydi
Javobingiz uchun tashakkur. Importdan so'ng - "ion-native" dan import {BarcodeScanner}; Shuningdek, bu xato
qo'shib qo'ydi muallif sukhesh chukkapalli, manba

1.Add the plugin to your app see below

ionic plugin add phonegap-plugin-barcodescanner

npm install --save @ionic-native/barcode-scanner

2.import

import { BarcodeScanner } from 'ionic-native';

import * as xml2js from "xml2js";

  1. BarcodeScanner.scan().then((barcodeData) => {

var name,uid;

xml2js.parseString(barcodeData.text,{trim: true}, function (err, result) { debugger;

name=result.PrintLetterBarcodeData.$.name; uid=result.PrintLetterBarcodeData.$.uid; });

debugger; this.AdharCardName=name; this.AdharcardUid=uid;
}, (err) => {

});

0
qo'shib qo'ydi

Barcode Scanner dasturini ishlatish uchun siz qo'shishingiz kerak

import { BarcodeScanner } from 'ionic-native';

va shunga o'xshash funktsiyani yaratish

barcode() {
  BarcodeScanner.scan()
  .then((result) => {
     if (!result.cancelled) {
       alert("Success"+result);
     }
  })
  .catch((err) => {
    alert(err); 
   })
 }

endi shtrix() funksiyasini qidirib topish uchun html-da istalgan joyga qo'ng'iroq qilishingiz mumkin

0
qo'shib qo'ydi
Javobingiz uchun tashakkur.
qo'shib qo'ydi muallif sukhesh chukkapalli, manba

Siz quyidagilarni qo'shishingiz kerak:

import { BarcodeScanner } from 'ionic-native';

Shundan so'ng shtrix kod yoki qr kodidan ma'lumotlarni olish uchun BarcodeScanner.scan() usullaridan foydalanishingiz mumkin. Ushbu kodni ko'ring: home.ts

import { Component } from '@angular/core';    
import { NavController } from 'ionic-angular';
import { BarcodeScanner } from 'ionic-native';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {}

  click() {
    BarcodeScanner.scan()
      .then((result) => {
        alert(
          "We got a barcode\n" +
          "Result: " + result.text + "\n" +
          "Format: " + result.format + "\n" +
          "Cancelled: " + result.cancelled
        )
      })
      .catch((error) => {
        alert(error);
      })
  }
}

home.html


  
    
      Ionic Blank
    
  



  

Scan

  <button block (click)="click()" color="primary">Scan</button>

0
qo'shib qo'ydi
Skanerni android-ga qanday qilib bekor qilsam bo'ladi?
qo'shib qo'ydi muallif Sboniso Marcus Nzimande, manba
Be e'lon qilingan cordoba bilan chiziqni o'chirish; Faqat BarcodeScan ob'ektini ishlating
qo'shib qo'ydi muallif Jorge Luis Jiménez, manba
Brauzerda harakat qilyapsizmi? Siz telefonda test qilishingiz kerak, chunki bu tabiiy funktsiya.
qo'shib qo'ydi muallif Jorge Luis Jiménez, manba
Scan() usulini ishlatmoqchi bo'lganingizda ham cordova.plugin-ni olib tashlang. Faqat BarcodeScanner.scan ()
qo'shib qo'ydi muallif Jorge Luis Jiménez, manba
Javobingiz uchun tashakkur. Importdan so'ng - "ion-native" dan import {BarcodeScanner}; Shuningdek, bu xato
qo'shib qo'ydi muallif sukhesh chukkapalli, manba
Rahmat. Xato hal qilindi, ammo "cordova_not_available" bilan ogohlantirish qutisini ko'rsatadi.
qo'shib qo'ydi muallif sukhesh chukkapalli, manba
Katta rahmat. U ishlaydi
qo'shib qo'ydi muallif sukhesh chukkapalli, manba
Angular Uzbekistan
Angular Uzbekistan
107 ishtirokchilar

Guruh Angular bo'yicha muloqot qilish uchun ochilgan Sizni qiziqtirsa: @nodejs_uz @react_uz @angular_uz @yiiframework_uz @js_uzb @typescript_uzb @vuejs_uz @ngTashkent @laravel_uz @uzdevgroup Ish o'rinlari @UzDev_jobs

ngTashkent
ngTashkent
77 ishtirokchilar

Правила просты: 1. Не хамить 2. Не хейтить 3. Реакт не нужен Ссылки: https://t.me/angular_ru - старший брат https://t.me/angular_uz - ангулар на узбекском @js_uzb @vuejs_uz @react_uz @nodejs_uz @yiiframework_uz @uzdevgroup @UzDev_Jobs @tasdev_talks