Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up
app.controller('getUser', function ($scope, $http, $cookieStore) {

$http.get('http://localhost:8080/myapp/user/'.concat($scope.getUserId) + '?access_token=' + $cookieStore.get("access_token")).
        then(function (response) {
            $scope.users = response.data;
        });});

    Table name: user{ id  | userDate | 1 |  2016-11-28 05:30:00.0}

<div ng-controller="getUser">
<label class="control-label">Date</label>
<input type="date"  class="form-control" ng-model="users.userDate" ng-value="{{users.userDate"}}">
</div>

Its not displaying date in date picker. Could you give me solution. Thanks

share|improve this question
    
I presume users contains actually one user. So... what do you need for ng-value="{{users.userDate"}}" when you have already a ng-model="users.userDate"? – Asiel Leal Celdeiro Nov 29 at 3:46
    
it would appear you have an extra " ng-value="{{users.userDate"}}" – haxxxton Nov 29 at 3:56
up vote 0 down vote accepted

you have to add this to your html

<input type="date" class="form-control" ng-model="users.userdate">

As the above line is expecting date object which you are not passing as you are passing date as a string.

and add this line to your script after you fetch your data.

$http.get('http://localhost:8080/myapp/user/'.concat($scope.getUserId) + '?access_token=' + $cookieStore.get("access_token")).
    then(function (response) {
        $scope.users = response.data;
        $scope.users.userdate = new Date($scope.users.userdate); // converting into date object which will display date in correct form in your html
    });});

If you don't want to add the above script then you can make your input tag type="text" which will work fine but it will not popup datepicker.

share|improve this answer
    
you also have an extra attribute which is not at all needed ng-value="{{users.userDate}}" – ashishraaj Nov 29 at 6:22

try this

small change required

 <input type="date"  class="form-control" ng-model="userdate" >

controller

 $scope.userdate= new Date(users.userDate);
share|improve this answer

Refer documentation

You need to provide the value to <input type='date'> in the correct acceptable format (YYYY-MM-DD) for it be shown correctly in the HTML5 date input.

You should be able to use filters to format date (in yyyy-MM-dd format) or do it in the controller itself before rendering it in the html template.

<input type="date"  class="form-control" ng-model="users.userDate" ng-value="{{users.userDate | date: 'yyyy-MM-dd'}}">
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.