我试图在主页中创建一个模态窗口,当用户从该单选组中选择一个值时,将其传递给单选组,然后让我的模态再次将他们选择的对象传递回首页
广播组页面和html
export class PopoverstationsPage implements OnInit {
cities :any
constructor(public nav : NavController,public nav : NavController,public modalController: ModalController ,public router : Route) { }
ngOnInit() {
console.log(this.cities)
}
onRadioChange(cities: Tab1Page):void {
this.modalController.dismiss(cities);
console.log(this.cities)
}
}
html
<ion-list>
<ion-radio-group (ionChange)="onRadioChange()" [(ngModel)]="cities">
<ion-list-header>
<ion-label>Name</ion-label>
</ion-list-header>
<ion-item>
<ion-label>ميناء خصب</ion-label>
<ion-radio slot="start" value="26.2105,56.244" ></ion-radio>
</ion-item>
<ion-item>
<ion-label>مطار خصب</ion-label>
<ion-radio slot="start" value="26.161722,56.23672"></ion-radio>
</ion-item>
<ion-item>
<ion-label>دبا</ion-label>
<ion-radio slot="start" value="25.615627,56.247322"></ion-radio>
</ion-item>
<ion-item>
<ion-label>البريمي</ion-label>
<ion-radio slot="start" value="24.233913,55.916176"></ion-radio>
</ion-item>
</ion-radio-group>
</ion-list>
上面的主页接收值表单页面,然后将其用于测试功能天气
export class HomePage implements OnInit {
cities :any
constructor(public nav : NavController,public modalController: ModalController) { }
ngOnInit() {
console.log(this.cities)
}
async openUserModal() {
const modal = await this.modalController.create({
component: PopoverstationsPage,
componentProps: { cities: this.cities },
});
modal.onDidDismiss()
.then((data) => {
const cities= data
console.log(cities)
});
return await modal.present();
}
async test (){
this.https.get('weather/'+this.cities+'.json')
.subscribe(data => {
this.weather = data
})
}
}
当数据ara返回l在[object Object]
中得到onDidDismiss
时!有什么想法吗?
答案 0 :(得分:0)
要查看实际数据,您需要执行以下JSON.stringify,
modal.onDidDismiss()
.then((data) => {
const cities= data;
console.log(JSON.stringify(cities));
});
答案 1 :(得分:0)
最终我确定了
modal.onDidDismiss().then((r) => {
console.log("the result:", r , 'test'+ this.testy);
this.testy = r.data.result
});