Как проверить дату начала и окончания в угловом шаблонном подходе?
У меня есть 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 ответ
Решение
Ты можешь использовать 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}}">