2

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");
Thomas Bormans
  • 5,156
  • 6
  • 34
  • 51
Irfan
  • 161
  • 1
  • 12

2 Answers2

2

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

MasterMohsin
  • 158
  • 14
-1

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

Community
  • 1
  • 1
Hardik Vaghani
  • 2,163
  • 24
  • 46
  • Still not resolved i am getting this error [ngModel:datefmt] Expected `10:45` to be a date – Irfan Jun 15 '16 at 07:26
  • It means time is not parsed as date which is required to be in date format. You have to parse data in proper date format which is expected. It is parsing '10:45' as string so error is encountered. – Hardik Vaghani Jun 15 '16 at 07:29
  • i have used this to parse $scope.demoTime = new Date("10:45"); error is removed but it is not setting to the input field – Irfan Jun 15 '16 at 07:36