【问题标题】:Ionic 5: DateTime does not work inside SegmentButtonIonic 5:DateTime 在 SegmentButton 中不起作用
【发布时间】:2020-07-18 04:23:34
【问题描述】:

我试图在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>

但是,单击按钮时日期选择器没有显示。

【问题讨论】:

    标签: angular ionic-framework ionic5


    【解决方案1】:

    我最终通过@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();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-09
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 2020-07-22
      • 2021-02-26
      • 1970-01-01
      相关资源
      最近更新 更多