我使用日期範圍的引導datetimepicker。我試圖在angularjs控制器中獲取日期值,如下所示。我也嘗試了一些從stackoverflow帖子的其他方法。但是,我做了什麼,我把日期值作爲控制檯日誌中的'空字符串'。Datetimepicker返回一個空字符串作爲值
我已經在這個順序
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/locale/en-gb.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/js/bootstrap-datetimepicker.min.js"></script>
相關發行最少的HTML代碼中添加的資源。
<div class="container">
<div class='col-md-3'>
<div class="form-group">
<div ng-show="value == 'showSearch2'" class='input-group date' id='datetimepicker6'>
<input type='text' ng-model="startDate" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
在控制器
$(function() {
$('#datetimepicker6').datetimepicker({
format : 'YYYY-MM-DD HH:mm:ss'
});
$("#datetimepicker6").on("dp.change", function(e) {
$('#datetimepicker7').data("DateTimePicker").minDate(e.date);
$scope.startDate = $("#datetimepicker6").val();
alert("selected date is " + $scope.startDate);
});
});
你使用角js? – Aravind
是的,我正在使用angularjs – user3844782
其中是angular.js腳本引用?請至少用控制器更新您的角碼。 btw任何下面的答案工作? – Aravind