<md-input-container>
<label>Enter date</label>
<md-datepicker ng-model="newResearch.plannedStartDate"></md-datepicker>
</md-input-container>
計劃開始至今的值爲「1985-03-05T16:00:00.000Z」 我需要的價值是完全只有1985年3月5日。角材質的DatePicker NG-模型包括時間
<md-input-container>
<label>Enter date</label>
<md-datepicker ng-model="newResearch.plannedStartDate"></md-datepicker>
</md-input-container>
計劃開始至今的值爲「1985-03-05T16:00:00.000Z」 我需要的價值是完全只有1985年3月5日。角材質的DatePicker NG-模型包括時間
在您的控制器,請將此:
var newDate = $filter('date')(value, "yyyy-MM-dd");
$scope.newResearch.plannedStartDate = newDate;
通過使用過濾器,你可以實現你的需求。
這是不可能的,因爲ng-model
需要日期。從docs:
「1985-03-05T16:00:00.000Z」 實際上是console.log()
顯示日期對象的方式(可能透過JSON.stringify())。
如果選中此CodePen,你會看到下面的代碼行:
console.log(typeof $scope.newResearch.plannedStartDate);
// This is a check for a Date object from Christoph's answer - http://stackoverflow.com/a/643827/782358
console.log(typeof $scope.newResearch.plannedStartDate.getMonth === 'function');
console.log(JSON.stringify($scope.newResearch.plannedStartDate));
產生下面的輸出:
我真的很想有一個自動綁定到變量「newResearch.plannedStartDate」在日期選擇器中使用ng-model。在控制器中使用它需要在轉換之前觸發某些內容。 –
當你需要在數據庫中保存日期時,以及在md-datepicker中顯示日期時,請不要忘記在mysql中將該字段的數據類型保存爲日期。 – Jigar7521