Irfan Irfan - 5 months ago 60
AngularJS Question

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

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");

Answer

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');

Comments