Yuyang He
Yuyang He

Reputation: 2272

ionic2 - self.parentView.context.zoomImage is not a function

When I use PhotoViewer plugin, this error coming out which testing in web, but when I run in my devices that PhotoViewer function can run without error.

.html file

<ion-content padding>
    <ion-card>
        <ion-card-content>
            <img [src]="education.Preview_image1" (click)="zoomImage(education.Preview_image1)"/>
        </ion-card-content>
    </ion-card>

</ion-content>

.ts file

import { PhotoViewer } from '@ionic-native/photo-viewer';

private photoViewer: PhotoViewer

zoomImage(imageData) {
      this.photoViewer.show(imageData);
  }

ERROR: enter image description here

Upvotes: 0

Views: 59

Answers (2)

RobrechtVM
RobrechtVM

Reputation: 936

Cordova is not available in browser. For that reason I like to test native functionalities in an emulator with ionic cordova emulate. Make sure you have an Android device running in Android Studio or you have setup Xcode properly for emulating

If you want to test in browser without adding it as a platform you can import Platform and check if cordova is available. Your functionality won't be testable but at least you got no warnings that way

import { Platform } from 'ionic-angular';

...

if(platform.is('cordova'))

...

Upvotes: 0

David
David

Reputation: 7507

When you use ionic serve cordova plugins will not be available. Cordova is only available if you run a platform.

You can run cordova in the browser by adding the platform: cordova platform add browser and then running it: cordova platform run browser. Make sure the plugin you want to use actually supports the browser platform (you can check the plugin.xml of the plugin, to be sure).

Upvotes: 1

Related Questions