当表单项位于 ionic v6 上的 ng 模板内时,我无法获取表单项的值



我有这个表单,当我提交表单时,我无法获得"fechaAntecedente";值,这是ng模板内的离子日期时间,提前感谢。

<form #fForm3="ngForm">
.
.
.
<ion-item button="true" id="open-date-input">
<ion-label>Fecha</ion-label>
<ion-text slot="end">{{ dateValue }}</ion-text>
<ion-popover trigger="open-date-input" show-backdrop="false" >
<ng-template>
<ion-datetime
name="fechaAntecedente"
presentation="date"
#popoverDatetime
(ionChange)="dateValue = formatDate(popoverDatetime.value)"
[(ngModel)]="form3.fechaAntecedente"
>
</ion-datetime>
</ng-template>
</ion-popover>
</ion-item>
.
.
.
</form>

如果我不使用ng模板,我可以从表格中获得值,但它不会在覆盖中显示日期

.html文件

<ion-item lines="full" button="true" id="open-date-input">
<ion-icon name="open-sharp" slot="start" class="detail_icon" color="primary"></ion-icon>
<ion-label slot="end" class="detail_note"> Date of Purchase </ion-label>
<ion-label class="detail_title ion-text-wrap">{{ dateValue }}</ion-label>
<ion-popover trigger="open-date-input" show-backdrop="false">
<ng-template>
<ion-datetime #popoverDatetime presentation="date"
(ionChange)=" dateValue=formatDate(popoverDatetime.value)">
</ion-datetime>
</ng-template>
</ion-popover>
</ion-item>

.ts文件

import { DatePipe } from '@angular/common'
export class page implements OnInit {
dateValue = '';
constructor( public datepipe: DatePipe ) { }
formatDate(value: string) {
return this.datepipe.transform(value, 'yyyy-dd-MM');
}
}

现在,在ts文件中,您可以使用属性dateValue获取日期。如果您有任何疑问,请在提交表格时使用console.log(this.dateValue(检查日期。

最新更新