how to set default time to html input field of type time in ionic

流过昼夜 提交于 2021-01-27 20:31:41

问题


I am new to Ionic, I am using html input field of type time for getting time picker in Ionic, I want to set some default time to that input field. I tried the following code.

<label class="item item-input">
    <span class="input-label">Time</span>
    <input type="time" ng-model="demoTime">
</label>

My controller has:

$scope.demoTime = new Date("10:45 AM");

回答1:


javaScript doesn't have times solely, we need to provide the parameter ans date-times.

You can do this in following way

<label class="item item-input">
      <span class="input-label">Time</span>
      <input type="time" ng-model="demoTime">
    </label>

In your controller set time like this

$scope.demoTime = new Date (new Date().toDateString() + ' ' + '10:45');




回答2:


You can assign value by

$scope.demoTime = "10:45";

OR

<input type="time" value="10:45">

since input type time is based on 24hour time format.

Similar question is answered here



来源:https://stackoverflow.com/questions/37827801/how-to-set-default-time-to-html-input-field-of-type-time-in-ionic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!