0

I tried to insert the following code in my page:

<md-datepicker ng-model="ctrl.myDate" md-placeholder="Enter date"></md-datepicker>

The myDate came correctly in the controller but it doesn't appear in the page in the field: date

UPDATE:

<form ng-submit="save()" class="form" role="form">
  <div class="col-md-2" id="dateContainer">
    <div class="form-group">
      <label for="dataCreazione">Data creazione</label>
      <md-datepicker ng-model="dataCreation" class="classDate" md-placeholder="Enter date">
      </md-datepicker>
    </div>
  </div>
  <button type="submit" class="btn btn-default btn-lg">Save</button>
</form>

The controller containes:

var $scope.dataCreation = new Date();
$scope.save = function() {
  console.log("the date of creation = " + $scope.dataCreation);
}
Matthew Cawley
  • 2,688
  • 1
  • 8
  • 19
selma
  • 77
  • 2
  • 12
  • 1
    can you share more code, if possible a working example? – Naren Murali Sep 17 '17 at 11:16
  • i updated my question , i got the code from https://material.angularjs.org/latest/demo/datepicker – selma Sep 17 '17 at 11:40
  • Is this what's needed? [Codepen](https://codepen.io/kai1992cool/pen/MEaOav) The problem was you were mixing `this` and `$scope` syntax incorrectly, Refer [here](https://stackoverflow.com/questions/11605917/this-vs-scope-in-angularjs-controllers) – Naren Murali Sep 17 '17 at 11:46
  • `var $scope.dataCreation = new Date();` is a syntax error, you don't need to use `var` to declare a variable on the `$scope`. – Matthew Cawley Sep 17 '17 at 11:54
  • i don't know but even when i changed all the scope with this , the problem remain – selma Sep 17 '17 at 12:06
  • There doesn't appear to be anything else wrong with the code. @NarenMurali has provided a [working pen using your code](https://codepen.io/kai1992cool/pen/MEaOav). Are you able to use that to see what is different? – Matthew Cawley Sep 17 '17 at 12:26
  • i followed the code with codepen but in my code doesn't work, really strange, is there any other way to pick a date with angularjs without this md-datepicker? – selma Sep 17 '17 at 12:55
  • @selma Could you reshare the codepen which you implemented form my original codepen here, then we can look into the issue even more? – Naren Murali Sep 17 '17 at 14:03

0 Answers0