嗨,我是离子的新手,我正在尝试将扫描信息从一个页面传递到另一个页面,当我执行程序时,我有一个console.log来检查信息是否正确传递但是在chrome console表示undefined,letme粘贴我的代码:
home.ts我尝试从扫描中发送信息:
import { Component } from '@angular/core';
import { NavController,Platform } from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
import { TabsPage } from '../tabs/tabs';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
private barcodeText:String;
private barcodeFormat:String;
private platform:Platform;
private navController:NavController;
constructor(private barcodeScanner: BarcodeScanner,public navCtrl: NavController,platform:Platform) {
this.platform = platform;
this.navController = navCtrl;
}
doScan(){
console.log('scannig product barcode');
this.platform.ready().then(() => {
this.barcodeScanner.scan().then((result) => {
if (!result.cancelled) {
this.barcodeText = result.text;
this.scanningDone(this.barcodeText)
}
}, (error) => {
console.log('error when scanning product barcode');
});
});
}
scanningDone(data){
this.navController.push(TabsPage,{
data:data
});
}
main.ts信息的地址:
import { Component } from '@angular/core';
import { NavController, NavParams , ToastController} from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
import { DetailsPage } from '../details/details';
import { Http } from '@angular/http'
@Component({
selector: 'main',
templateUrl: 'main.html'
})
export class MainPage {
information: any[];
item:any;
private bcData;
constructor(public navCtrl: NavController, private http: Http,public params:NavParams) {
this.bcData = params.get('data');
console.log(params.get('data'));
let localData = http.get(this.bcData).map(res => res.json().items);
localData.subscribe(data => {
this.information = data;
})
}
在console.log上的(params.get('data'));它是我在控制台上未完成的地方。
答案 0 :(得分:0)
如何使用 localStorage 看看this
答案 1 :(得分:0)
你可以在你的TabsPage中有一个处理打开和关闭页面的方法,如下所示:
openPages(Page, Data){
this.navCtrl.push(Page,Data);
}
然后在您的scanDone方法中:
scanningDone(data){
this.tabsPage.openPages(MainPage,{
data:data
});
}