【发布时间】:2018-05-01 15:29:36
【问题描述】:
我正在以角度构建组件,我希望开始日期大于结束日期。我想知道我需要对我的 HTML 和 TS 代码进行哪些更改才能完成它。我使用的 HTML 和 TS 代码的 sn-ps 是:
HTML:
<form class="unavailability-form" [formGroup]="unavailabilityForm" *ngIf="loaded">
<div class="component-title" matDialogTitle>
{{'PORTAL.TEXTUNAVAILABILITY' | translate}}
</div>
<mat-toolbar>
<div class="container"
fxLayout="row"
fxLayout.xs="column"
fxLayoutGap.xs="0">
<div>
<h1>{{componentTitle}}</h1>
</div>
</div>
</mat-toolbar>
<mat-dialog-content>
<div class="container" fxLayout="row" fxLayout.xs="column" fxLayoutGap.xs="0" fxLayoutGap="10px">
<div class="item item-1" fxFlex="50%" fxFlexOrder="1">
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="{{'PORTALSTARTDATE' | translate}}" type="text" formControlName="startDate" [(ngModel)]="availability.startDate" [readonly]="!componentPermission.writePermission">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
</div>
<div class="item item-2" fxFlex="50%" fxFlexOrder="1">
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="{{'PORTAL.ENDDATE' | translate}}" type="text" formControlName="endDate" [(ngModel)]="availability.endDate" [readonly]="!componentPermission.writePermission">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
</div>
</div>
<div class="item item-1" fxFlex="50%" fxFlexOrder="1">
<mat-form-field>
<input matInput placeholder="{{'PORTAL.UNAVAILABILITYREASON' | translate}}" type="text" formControlName="unavailabilityReason" [(ngModel)]="availability.unavailabilityReason" [readonly]="!componentPermission.writePermission">
</mat-form-field>
</div>
</mat-dialog-content>
<mat-dialog-actions>
<div class="container" fxLayout="row" fxLayout.xs="column" fxLayoutGap.xs="0">
<div class="item item-1" fxFlex="100%">
<button mat-raised-button color="primary" [disabled]="!locationForm.valid || !componentPermission.writePermission" (click)="onSave()">{{'PORTAL.CONFIRM' | translate}}</button>
<button mat-raised-button [matDialogClose]="canceled" color="primary">{{'PORTAL.CANCEL' | translate}}</button>
</div>
</div>
</mat-dialog-actions>
</form>
TS:
validateForm() {
this.unavailabilityForm = this.formBuilder.group({
'startDate': [''],
'endDate': [''],
'unavailabilityReason': ['']
});
}
在上面的代码中,{{PORTAL.___}} 文本是指数据库中的值。
【问题讨论】:
标签: angular validation date