Reputation: 13329
I used this plugin in ionic v1, workd fine. But Im not sure how to add it to Ionic 2
Cant build the project because it cant find 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 are doing the same. But how would it work if it does not find cordova, I mean cordova is only added once built isnt it??
Upvotes: 5
Views: 2428
Reputation: 4013
The main difference of your code and the example that you gave us is this one:
Example
app/pages/home/home.js
Your code (I would guess that you used ionic-cli to generate the page)
scan-vehicle-page.ts
Try with this:
(<any>cordova).plugins.pdf4157Scanner.scan();
That is a workaround to avoid issues with typescript, because cordova doesn't exists on that scope, but you know that it exists on runtime.
Upvotes: 5