1

In template:

<form role="form" ng-submit="submitQuery()">
    <div class="form-group">
    <label for="latestInput">ending time</label>
    <input type="datetime-local" id="latestInput" name="latestInput" 
     ng-model="latest" placeholder="yyyy-MM-ddTHH:mm" required />
    <input type="submit" id="submit" value="Submit">
    </div>
</form>

In controller:

var now = new Date();
$scope.latest = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes());

I'd like to have the latestInput set up to display time when user launched the page, it works in the documentation example but not in my code, nor in this plunker:

http://plnkr.co/edit/d91CZS88OsmJMt6oyo9p?p=preview

what's wrong with this?

Note: I had angular telling me

Octal literals are not allowed in strict mode.

when I tried to use new Date(2014, 29, 7, 10, 38); this is why I'm using now

datamosh
  • 130
  • 3
  • 10

2 Answers2

2

In your demo, you are using angular version 1.2.20 which is a stable release that does not have a support for datetime-local.

Updating the plunkr works for me. http://plnkr.co/edit/t3OqrDCQOsdm5AqLBSRY?p=preview

Always check the angular version (top left corner) the documentation is using: enter image description here

codef0rmer
  • 10,284
  • 9
  • 53
  • 76
1

The input type datetime-local is only supported from AngularJS 1.3.0.beta1 onwards (as well date, time, month and week):

https://github.com/angular/angular.js/blob/master/CHANGELOG.md#130-beta1-retractable-eyebrow-2014-03-07

mjtko
  • 1,040
  • 9
  • 12