Adding the cordova plugin to Ionic 2

I used this plugin in ionic v1, workd fine. But I'm not sure how to add it to Ionic 2

I can’t build a project because he can’t find the cordova

import { Component } from '@angular/core'; import { Platform, NavController, NavParams } from 'ionic-angular'; @Component({ selector: 'page-scan-vehicle', templateUrl: 'scan-vehicle.html' }) export class ScanVehiclePage { constructor(public platform: Platform, public navCtrl: NavController, public navParams: NavParams) {} public scan () { // open scanner // save results this.platform.ready().then(() => { cordova.plugins.pdf417Scanner.scan() }); } } 

Enev in this example , they do the same. But how does it work if he does not find the cord, I mean, the cord is added only after it is built, right?

+5
source share
1 answer

The main difference between your code and the example you gave us is the following:

Example

application / page / home / home. Js

Your code (I would assume that you used ionic-cli to create the page)

scan-vehicle-page. c

Try with this :

 (<any>cordova).plugins.pdf4157Scanner.scan(); 

This is a workaround to avoid typescript issues because cordova does not exist in this area, but you know that it exists at runtime.

+5
source

Source: https://habr.com/ru/post/1263325/


All Articles