I'm having trouble displaying and binding a base64 image as an ImageSource in my View. The image doesn't show up at all, and I couldn't find any helpful information about it in the documentation. Am I missing something?
The imageSource property is supposed to contain the Image src data.
Below is the code for the View:
<Page loaded = "loaded" xmlns = "http://schemas.nativescript.org/tns.xsd" >
<StackLayout>
<TextField hint = "String for encoding!" text = "{{ message }}" />
<Button tap = "{{ onGenerateQrTap }}" text = "Generate QR" class = "button" />
<Image src = "{{ imageSource }} " />
</StackLayout>
</Page>
Here is the code behind the View:
import { Page } from 'ui/page';
import { EventData } from 'data/observable';
import { QrGeneratorViewModel } from '../../ViewModels/QrGeneratorViewModel';
import { Button } from 'ui/button';
import { Image } from 'ui/image';
let viewModel = new QrGeneratorViewModel();
export function loaded(args: EventData) {
let page = <Page>args.object;
page.bindingContext = viewModel;
}
And here is the ViewModel:
import { Observable } from 'data/observable';
import { QrGenerator } from '../Common/QrGenerator';
import { ImageSource } from "image-source";
export class QrGeneratorViewModel extends Observable {
private _message: string;
private _qrGenerator: QrGenerator.Generator;
private _imageBase64String: string;
private _imageSource: ImageSource;
constructor() {
super();
this._qrGenerator = new QrGenerator.Generator();
this._imageSource = new ImageSource();
}
get message() {
return this._message;
}
set message(newMessage: string) {
this._message = newMessage;
}
get imageSource(): ImageSource {
return this._imageSource;
}
public onGenerateQrTap(): void {
this._imageBase64String = this._qrGenerator.qr(this._message);
this._imageSource.loadFromBase64(this._imageBase64String);
}
}