0
我正在使用來自github的datetimepicker library作爲我的角度項目。當我選擇日期和時間時,它工作正常。但是,當我將ng-model
添加到輸入字段並檢索它時,輸入字段顯示爲空。它不會基於ng模型更新字段。如何從輸入中獲取日期時間值
指令
App.directive('jsDatetimepicker', function() {
return {
link: function (scope, element, attrs) {
var options = (typeof scope.$eval(attrs.jsDatetimepicker) !== 'undefined') ? scope.$eval(attrs.jsDatetimepicker) : new Object();
jQuery(element).datetimepicker({
format: options.format ? options.format : false,
useCurrent: options.useCurrent ? options.useCurrent : false,
locale: moment.locale('' + (options.locale ? options.locale : '') +''),
showTodayButton: options.showTodayButton ? options.showTodayButton : false,
showClear: options.showClear ? options.showClear : false,
showClose: options.showClose ? options.showClose : false,
sideBySide: options.sideBySide ? options.sideBySide : false,
inline: options.inline ? options.inline : false,
icons: {
time: 'si si-clock',
date: 'si si-calendar',
up: 'si si-arrow-up',
down: 'si si-arrow-down',
previous: 'si si-arrow-left',
next: 'si si-arrow-right',
today: 'si si-size-actual',
clear: 'si si-trash',
close: 'si si-close'
}
});
}
};
});
HTML
<input id="example-datetimepicker5" data-js-datetimepicker="" type="text" name="example-datetimepicker5" placeholder="Choose a date.." ng-model="news.new_date" class="form-control"/>
<label for="example-datetimepicker5">Date</label>
<button ng-click="CreateNews()" type="button" class="btn btn-sm btn-primary"><i class="fa fa-check"></i> Create</button>
控制器
$scope.news = {};
$scope.news.new_date = "";
$scope.CreateNews = function(){
alert(JSON.stringify($scope.news.new_date));
}
輸出
new_date returns empty
預計
new_date returns datetime
我使用angularJS,jQuery的 '$' 應該忽略。 –
你可以在angularjs中使用JQuery,但是你需要爲它添加Lib –