[英]I can't get the value of a form item when it's inside an ng-template on ionic v6
我有这个表格,当我提交我的表格时,我无法获得“fechaAntecedente”值,这是 ng-template 中的离子日期时间,在此先感谢。
<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-template 我可以从表单中获取值,但它不会在叠加层中显示日期
.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) 检查日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.