Rajkumar Rajkumar - 6 days ago 6
AngularJS Question

how to display date only in datepicker from database using angularjs

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

Answer

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.

Comments