我需要在另一个页面的函数中使用声明的变量。让我解释一下:在主页上我用这张照片拍照:
capture(event, fab: FabContainer) {
fab.close();
const cameraOptions: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true
};
this.camera.getPicture(cameraOptions).then((imageData) => {
this.captureDataUrl = ('data:image/jpeg;base64,' + imageData);
this.upload();
}, (err) => {
});
}
现在我想将this.captureDataUrl
发送到过滤页面,制作一些内容并将其发送回主页以更新现有页面。这可能吗?
答案 0 :(得分:0)
您可以使用活动
在您的主页中会有类似
的内容capture(event, fab: FabContainer) {
fab.close();
const cameraOptions: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true
};
this.camera.getPicture(cameraOptions).then((imageData) => {
this.captureDataUrl = ('data:image/jpeg;base64,' + imageData);
this.events.publish('pictureEvent',{dataUrl:this.captureDataUrl})
this.upload();
}, (err) => {
});
}
在您的过滤器页面中,只需对事件进行处理并执行您需要执行的操作
import { Events } from 'ionic-angular';
...
constructor(private events:Events){
this.events.subscribe('pictureEvent',dataUrl=>console.log(dataUrl))
...
}
答案 1 :(得分:0)
使用navCtrl和navParams
解决