Im 使用 ionic 2 RC5。
在下面的扫描函数中,我称之为:
this.navCtrl.push(VerifyVehiclePage)
似乎"这个"在这个范围内是未知的:
Cannot read property 'navCtrl' of null
我不明白为什么,以及如何使其可用以便我可以使用导航控制器?
import { Component } from '@angular/core';
import { Platform, NavController } from 'ionic-angular';
import { VerifyVehiclePage } from '../verify-vehicle/verify-vehicle'
import { Setup } from '../../providers/setup'
declare var cordova:any;
@Component({
selector: 'page-scan-vehicle',
templateUrl: 'scan-vehicle.html'
})
export class ScanVehiclePage {
constructor(public platform: Platform, public navCtrl: NavController, public setup: Setup) {}
public scan () {
// import Entry Model
let entry = this.setup.getEntry()
var types = ["PDF417"];
var options = {
beep : true, // Beep on
noDialog : true, // Skip confirm dialog after scan
uncertain : false, //Recommended
quietZone : false, //Recommended
highRes : false, //Recommended
inverseScanning: false,
frontFace : false
};
var licenseiOs = "RZNIT6NY-YUY2L44B-JY4C3TC7-LE5LFU2B-JOAF4FO3-L5MTVMWT-IFFYAXQV-3NPQQA4G";
var licenseAndroid = "Y5AR6RJ4-PPA6ZDJ6-ABLKN4DE-XZEVSOLL-HLBOUBAE-AQCAIBAE-AQCAIBAE-AQCFKMFM";
var licenseWP8 = "5JKGDHZK-5WN4KMQO-6TZU3KDQ-I4YN67V5-XSN4FFS3-OZFAXHK7-EMETU6XD-EY74TM4T";
try {
cordova.plugins.pdf417Scanner.scan(
function callback(scanningResult) {
if (scanningResult.cancelled == true) {}
var resultList = scanningResult.resultList;
for (var i = 0; i < resultList.length; i++) {
var recognizerResult = resultList[i];
if (recognizerResult.resultType == "Barcode result") {
var disc = recognizerResult.data.split("%")
entry.vehicle.licence_number = disc[6]
entry.vehicle.register_number = disc[7]
entry.vehicle.vehicle_type = disc[8]
entry.vehicle.make = disc[9]
entry.vehicle.model = disc[10]
entry.vehicle.color = disc[11]
entry.vehicle.vin_number = disc[12]
entry.vehicle.engine_number = disc[13]
this.navCtrl.push(VerifyVehiclePage)
}
}
},function errorHandler(err) {alert('Error: ' + err)},types, options, licenseiOs, licenseAndroid, licenseWP8
);
} catch (err) {
entry.vehicle.licence_number = "CY12345"
entry.vehicle.register_number = "BFG1212F"
entry.vehicle.vehicle_type = "Pickup"
entry.vehicle.make = "Land Rover"
entry.vehicle.model = "Series 3"
entry.vehicle.color = "White"
entry.vehicle.vin_number = "36101299292020"
entry.vehicle.engine_number = "1234334"
this.navCtrl.push(VerifyVehiclePage)
}
}
}
更改
function callback(scanningResult) {
自
(scanningResult) => {
和
function errorHandler(err) {
自
(err) => {
另请参阅 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions