NathanaelA / nativescript-zxing

ZXing for NativeScript
Other
15 stars 22 forks source link

How to use into nativescript-angular? #14

Closed EduhCosta closed 6 years ago

EduhCosta commented 7 years ago

Sorry, but this application has implementation with the angular?

Thanks

matejhocevar commented 6 years ago

Hey, Im wondering the same thing. Any update on this topic?

Thanks

NathanaelA commented 6 years ago

Should work out of the box with NS-Angular.

matejhocevar commented 6 years ago

For future self :) Following code is working for me in Angular6.

// app.component.html
<Button (tap)="generateBarcode()" id="barcode" text="GENERATE BARCODE"></Button>
<Image #barcodeImg id="barcode-img" height="100" stretch="aspectFill" class="text-center"></Image>

 // app.component.ts
import { Image } from "tns-core-modules/ui/image";
import { TextField } from "ui/text-field";

const ZXing = require("nativescript-zxing");
const ImageSource = require("image-source");

export class AppComponent {
    @ViewChild("barcodeImg") barcodeImg: ElementRef;
    barcodeText = "00381500107604446618";
    ...

    generateBarcode() {
        const barcodeImage = <Image>this.barcodeImg.nativeElement;
        const zx = new ZXing();
        const newImg = zx.createBarcode({
            encode: this.barcodeText,
            format: ZXing.CODE_128
        });
        barcodeImage.imageSource = ImageSource.fromNativeSource(newImg);
    }
}
fernandomeneghetti commented 5 years ago

For future self :) Following code is working for me in Angular6.

// app.component.html
<Button (tap)="generateBarcode()" id="barcode" text="GENERATE BARCODE"></Button>
<Image #barcodeImg id="barcode-img" height="100" stretch="aspectFill" class="text-center"></Image>

 // app.component.ts
import { Image } from "tns-core-modules/ui/image";
import { TextField } from "ui/text-field";

const ZXing = require("nativescript-zxing");
const ImageSource = require("image-source");

export class AppComponent {
    @ViewChild("barcodeImg") barcodeImg: ElementRef;
    barcodeText = "00381500107604446618";
    ...

    generateBarcode() {
        const barcodeImage = <Image>this.barcodeImg.nativeElement;
        const zx = new ZXing();
        const newImg = zx.createBarcode({
            encode: this.barcodeText,
            format: ZXing.CODE_128
        });
        barcodeImage.imageSource = ImageSource.fromNativeSource(newImg);
    }
}

Hi,

Can you share the project? I tried to follow the steps, but to no avail. thank you