1

This might be a stupid and an easy problem but I can't seem to have a solution to this. I'm trying to set a field of type Date but nothing show up. Here is my code:

In Html:

<input type="date" name="departure" ng-model="departure" placeholder="yyyy-MM-dd" required/>

In the Controller I do something like this:

$scope.departure = new Date(2015, 9, 22);

NOTHING got display in the field "departure". I dont understand why. This seems to be so easy. I follow this example: https://docs.angularjs.org/api/ng/input/input%5Bdate%5D

Please help. I'm using Angular 1.3 Thanks

1
  • Make sure you set ng-controller in the html. Commented Nov 16, 2014 at 21:15

1 Answer 1

2

I assume you are just trying to get your scope variable departure to be translated into the format of the date input. I created this plunkr.

JS

var app = angular.module('stack',[]);

app.controller('DateController', ['$scope', function($scope){
    $scope.departure = new Date(2015, 10, 22);
}]);

HTML

<!DOCTYPE html>
<html ng-app="stack">

  <head>
    <script src="//code.angularjs.org/1.3.1/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-controller="DateController">
    <input type="date" name="departure" ng-model="departure" placeholder="yyyy-MM-dd" required/>
  </body>

</html>

Again not exactly sure what you were trying to do but this works for me. Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Just as a side note: The month index is zero-based, so new Date(2015, 10, 22) is the 22nd of November, 2015. Just in case anybody bumps into this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.