根据javascript中的当前小时禁用时隙

时间:2018-03-05 09:20:31

标签: javascript html angular typescript

我完成一件简单的事情。我想根据当前小时禁用时间段。即如果它是1PM我想禁用以前的时间段。 这是我的HTML:

    <div class="  col-sm-4  col-md-4  col-lg-4">
    <md-select placeholder="Select Time" name="type" class="wd-100pc[(ngModel)]="Input.timeslot">
      <md-option>Select Slot</md-option>
      <md-option value="7AM-8AM">7AM-8AM</md-option>
      <md-option value="8AM-9AM">8AM-9AM</md-option>
      <md-option value="9AM-10AM">9AM-10AM</md-option>
      <md-option value="10AM-11AM">10AM-11AM</md-option>
      <md-option value="11AM-12PM">11AM-12PM</md-option>
      <md-option value="12PM-1PM">12PM-1PM</md-option>
      <md-option value="1PM-2PM">1PM-2PM</md-option>
      <md-option value="2PM-3PM">2PM-3PM</md-option>
      <md-option value="3PM-4PM">3PM-4PM</md-option>
      <md-option value="4PM-5PM">4PM-5PM</md-option>
      <md-option value="5PM-6PM">5PM-6PM</md-option>
      <md-option value="6PM-7PM">6PM-7PM</md-option>
      <md-option value="7PM-8PM">7PM-8PM</md-option>
      <md-option value="8PM-9PM">8PM-9PM</md-option>
    </md-select>
  </div>

我如何使用打字稿来完成这个。我在角度2做这个。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您只需dategetHours功能

即可

组件方:

hours = new Date().getHours(); // will return 24 hours

模板面:

<md-select placeholder="Select Time" name="type" class="wd-100pc[(ngModel)]="Input.timeslot">
    <md-option>Select Slot</md-option>
    <md-option value="7AM-8AM" [disabled]='7 <= hours'>7AM-8AM</md-option>
    <md-option value="8AM-9AM" [disabled]='8 <= hours'>8AM-9AM</md-option>
    ....
</md-select>