user6086034
user6086034

Reputation:

How to set date of input type="date" based on ng-model value

I have a date in $scope. When the page loads I want the input type="date" field value to be set on the value in $scope.

<input class="form-control" type="date"
        ng-model="asso.formation_of_association"
        placeholder="" />

But I only see dd-mm-yyy on the input field

Upvotes: 0

Views: 49

Answers (2)

samplename
samplename

Reputation: 1

check the type of the ng-model value with typeof

if the typeof returns a date replace in your input file with type date

Upvotes: 0

webmazz
webmazz

Reputation: 116

You should show your code becouse I prepared an example and it works.

<div ng-app>
  <div ng-controller="myCtrl">
    <input type="date" ng-model="date.formation_of_association">
  </div>
</div>

function myCtrl($scope) {

  $scope.asso = {
    'formation_of_association': '2018-06-21'
  };

}

Upvotes: 1

Related Questions