如何在角度模板驱动方法中验证开始和结束日期?

时间:2018-04-02 06:04:55

标签: angular date angular-validation

我的表单中有2个日期输入,如下所示:

<label class="control-label">Start Date</label>
    <input type="date" name="startDate" placeholder="Start Date" class="form-control" ngModel required #startDate="ngModel">
    <span *ngIf="!startDate.valid && startDate.touched" class="error-msg">
     <span *ngIf="startDate.errors.required">Start Date is required</span>
     </span>
     <br/>
 <label class="control-label">End Date</label>
 <input type="date" name="endDate" placeholder="End Date" class="form-control" ngModel required #endDate="ngModel" >
    <span *ngIf="!endDate.valid && endDate.touched" class="error-msg">
    <span *ngIf="endDate.errors.required">End Date is required</span>
    </span>

我想让用户只选择开始日期的日期。我尝试使用min属性但无法正常工作

1 个答案:

答案 0 :(得分:1)

您可以使用min属性

 <label class="control-label">End Date</label>
 <input type="date" name="endDate" placeholder="End Date" class="form-control" ngModel required #endDate="ngModel" min="{{your_form_name.value.startDate}}">