Angular 财产';ONDIDDESCLISH';离子4型和角型上不存在
我正在开发一个应用程序,下一节课是TypeScript 我想尝试在“ModalController”中的回调类型方法中获取数据,当它关闭模态时:Angular 财产';ONDIDDESCLISH';离子4型和角型上不存在,angular,typescript,ionic-framework,ionic4,Angular,Typescript,Ionic Framework,Ionic4,我正在开发一个应用程序,下一节课是TypeScript 我想尝试在“ModalController”中的回调类型方法中获取数据,当它关闭模态时: import { Component, OnInit } from '@angular/core'; import {NavController, ModalController} from '@ionic/angular'; import { Router } from '@angular/router'; import { HomePage
import { Component, OnInit } from '@angular/core';
import {NavController, ModalController} from '@ionic/angular';
import { Router } from '@angular/router';
import { HomePage } from '../home/home.page';
import {AddItemPage} from '../add-item/add-item.page';
@Component({
selector: 'app-todo',
templateUrl: './todo.component.html',
styleUrls: ['./todo.component.scss']
})
export class TodoComponent implements OnInit {
public items;
constructor(public navCtrl: NavController, public modalCtrl: ModalController) {
this.ionViewDidLoad();
}
ngOnInit() {}
async addItem() {
// Create a modal using MyModalComponent with some initial data
const modal = await this.modalCtrl.create({
component: AddItemPage, componentProps: {
'prop1': "cadena!!!!!!!"
}
}).then(function(modal) {
return modal.present();
});
modal.onDidDismiss(() => {
// Call the method to do whatever in your home.ts
console.log('Modal closed');
});
}
}
我得到了这个错误:
core.js:15724错误:未捕获(承诺中):TypeError:Cannot
读取undefinedTypeError的属性“OnDidDisclesh”:无法读取
未定义的属性“OnDidDisclesh”
由于您正在使用
wait
创建模式,因此不需要像这样使用then
请尝试以下操作:
async addItem() {
// Create the modal
const modal = await this.modalCtrl.create({
component: AddItemPage,
componentProps: {
'prop1': "cadena!!!!!!!"
}
});
// Present the modal
return await modal.present();
// Wait for the modal to be dismissed before continuing...
const eventDetails = await modal.onDidDismiss();
if (eventDetails) {
console.log(eventDetails.data);
}
// ...
}
上面的代码假设您在解除模态时返回了一些内容,如下所示:
// Dismiss the modal returning some data object
modalController.dismiss({
'result': 'This is the result returned by the modal!'
});
尝试:
按照官方的说法 这篇文章中的关系如何: 我的错误只是我如何创建模态。我按照这段代码创建了我的模态属性
async openModal() {
const modal: HTMLIonModalElement =
await this.modalController.create({
component: DatePickerModal,
componentProps: {
aParameter: true,
otherParameter: new Date()
}
});
modal.onDidDismiss().then((detail: OverlayEventDetail) => {
if (detail !== null) {
console.log('The result:', detail.data);
}
});
await modal.present();
}
@FernandoPie你能解决这个问题吗?@Sebafereras哦,是的,sebas我在这里找到了我的解决方案:@FernandoPie好的,很高兴听到你解决了这个问题。当提出关于SO的问题时,请花一些时间查看答案,看看其中是否有任何答案可以解决您的问题,如果没有,并且您找到了更好的解决方案,您可以添加自己的答案。这样你就可以接受答案并结束问题。否则,您的问题将保持开放状态,这会让其他用户认为它根本没有解决方案。我们的目标只是帮助其他面临同样问题的用户找到解决方法。
async openModal() {
const modal: HTMLIonModalElement =
await this.modalController.create({
component: DatePickerModal,
componentProps: {
aParameter: true,
otherParameter: new Date()
}
});
modal.onDidDismiss().then((detail: OverlayEventDetail) => {
if (detail !== null) {
console.log('The result:', detail.data);
}
});
await modal.present();
}