【发布时间】:2019-06-12 23:26:20
【问题描述】:
我在这里寻找过类似的问题,但找不到足够类似的问题。 将 Ionic 4 与 Angular 7 Typescript 3.16 一起使用 我有几个'TimeSpan'值我需要得到所以有一个来自html的函数,如下所示:
<ion-input type="text" (click) =" getTypTime()" ....>
这个点击处理程序是这样的:
getTypTime() { // Gets the typical time
const currentTime = this.service.TimeToDoTypicalOrBestCase;
this.getTime(currentTime).then( res => {
console.log('GetTypTime result :'); // **3**
console.log(res);
});
}
呈现picker并获取结果的函数如下:
async getTime(inputTime: TimeSpan) {
console.log(inputTime); // **1**
const opts: PickerOptions = {
buttons: [
...more stuff...
],
columns: [
{
name: 'Hours',
...more stuff...
]
},
{
name: 'Mins',
...more stuff...
}
]
};
const picker = await this.pickerCtrl.create(opts);
console.log('Presenting picker'); // **2**
picker.present();
picker.onDidDismiss().then(() => {
picker.getColumn('Hours').then( colh => {
this.pickedTime.hours = colh.options[colh.selectedIndex].value;
picker.getColumn('Mins').then( colm => {
this.pickedTime.minutes = colm.options[colm.selectedIndex].value;
console.log(this.pickedTime); // **4**
return this.pickedTime.ToString();
});
});
});
}
日志输出:
00:30:00 (This is a the top of the function **1** see code)
Presenting picker (This is towards the end of the function **2**)
GetTypTime result : undefined (This is in the CALLING function **3**)
(The following line displayed after the dismiss **4**)
TimeSpan {_seconds: 0, _minutes: 0, _hours: 0, _ days: 0, _milliseconds: 0, …}
该函数显然在从选择器的 ondismiss 实际返回之前返回,但我觉得这应该有效。谁能指出我哪里出错了..?
我已将其更改为不再使用 await... 之前,它是这样的:
picker.onDidDismiss().then(async () => {
let col = await picker.getColumn('Hours');
this.pickedTime.hours = col.options[col.selectedIndex].value;
col = await picker.getColumn('Mins');
this.pickedTime.minutes = col.options[col.selectedIndex].value;
console.log(this.pickedTime);
return this.pickedTime.ToString();
});
}
但这没有用,所以我对其进行了修改以删除等待.. 想法?
【问题讨论】:
标签: angular typescript ionic4