2016-11-29 31 views
1
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> 

它不在日期選擇器中顯示日期。你能給我解決方案嗎? 由於如何使用angularjs從數據庫中僅顯示datepicker中的日期

+0

我相信* *用戶實際上包含一個用戶。所以......你需要什麼的'NG值=「{{users.userDate」}}「'當你已經一個'NG-模型=」 users.userDate「'? – lealceldeiro

+0

它會出現在你有一個額外的' 「''NG值=」{{users.userDate 「}}」' – haxxxton

回答

0

你必須把它添加到您的HTML

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

作爲上述線期待你不傳遞作爲要傳遞日期作爲一個字符串日期的對象。

和此行您將獲取您的數據後,添加到您的腳本。

$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 
    });}); 

如果你不想添加上面的腳本,那麼你可以讓你的輸入標籤type="text"這將正常工作,但它不會彈出日期選擇器。

+0

你也有這是不是在所有需要'NG-值的額外屬性= 「{{users.userDate}}」' – ashishraaj

0

documentation參見

您需要提供value<input type='date'>在正確的可接受的格式(YYYY-MM-DD)爲它在HTML5日期輸入正確顯示。

您應該能夠使用過濾器格式日期(yyyy-MM-dd格式)或HTML模板渲染之前,做在控制器中。

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

試試這個

小的變化需要

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

控制器

$scope.userdate= new Date(users.userDate); 
相關問題