我尝试在ion-segment-button中放置一个ion-datetime元素。这样做是为了模拟“今天”、“昨天”和自定义日期之间的日期选择。代码如下所示:
<ion-segment mode="md" [(ngModel)]="dateSegment">
<!-- Other buttons -->
<ion-segment-button value="OTHER" color="primary">
<ion-datetime [(ngModel)]="selectedDate"></ion-datetime>
</ion-segment-button>
</ion-segment>但是,单击该按钮时没有显示日期选择器。
发布于 2020-07-18 04:23:34
我最终实现了一种变通方法,通过@ViewChild打开按钮单击时的DateTime,如here所述
在模板中:
<ion-segment-button value="OTHER" (click)="openDateTime()">
<ion-datetime #dateTime [(ngModel)]="selectedDate"></ion-datetime>
</ion-segment-button>在组件中:
export class MyComponent {
@ViewChild('dateTime', { static: true }) dateTime: IonDatetime;
openDateTime() {
this.dateTime.open();
}
}https://stackoverflow.com/questions/62961304
复制相似问题