I am using cordova-plugin-camera within my Ionic 2 app. I can successfully take a photo and then alert the value of selfieImage - this shows me data:image/jpeg;base64, followed by the base64 encoded version of my image - great
takeRegistrationSelfie() {
Camera.getPicture({
destinationType: Camera.DestinationType.DATA_URL,
targetWidth: 1000,
targetHeight: 1000,
correctOrientation: true,
cameraDirection: 1
}).then((imageData) => {
// imageData is a base64 encoded string
this.selfieImage = "data:image/jpeg;base64," + imageData;
}, (err) => {
console.log(err);
});
}
Within my template I have
<img [src]="selfieImage" *ngIf="selfieImage" />
At this point selfieImage is defined but my image is empty - 10 x 10 pixels, grey border, no image.
Later on in my app I send an ajax request with the image to my backend - this works fine and the image is received correctly.
Why won't the image show within my template?
Try with ngZone to make Angular detect the change.
Or I had done this using
FILE_URL
.I have discovered that I need to use DomSanitizer. With this in place then the image works.
In my constructor I have ...
And then in my template ...
Voila, it works :-)
Edit. I have been asked for a full version of my code. I'll add it below.
Have you tried