以下代碼與純正angularjs正確搭配使用,但是當我將其集成到Mobile Angular UI App時,它在選擇日期後不會更新模型。如果我編輯沒有日期選擇器的輸入字段,它工作正常。選擇日期後型號未更新
模板:
<div>
<label>{{myLabel}}:</label>
<input class="form-control datetime-picker" placeholder="{{myPlaceholder}}" ng-model="ngModel" required="required">
</div>
指令JS代碼:
(function(){
var app = angular.module('MeetingApp.directives.HelpDirective', []);
app.directive("datetimePicker", function() {
return {
restrict: 'E',
templateUrl: "datetime-picker.html",
scope: {
ngModel: '=',
myPlaceholder: '@',
myLabel: '@'
},
require: ['?^ngModel'],
link: function(scope, element, attrs, ngModelCtrl) {
$(element).find('.datetime-picker').datetimepicker({
format: "dd.mm.yyyy hh:ii",
autoclose: true,
language: "de",
startDate: new Date(),
minuteStep: 10
});
}
};
});
})();
用法:
<form method="post" id="meetingForm" ng-controller="MeetingController as meetingCtrl" novalidate>
<datetime-picker my-placeholder="Startzeit" my-label="Startzeit" ng-model="meetingCtrl.meeting.start"></datetime-picker>
<datetime-picker my-placeholder="Endzeit" my-label="Endzeit" ng-model="meetingCtrl.meeting.end"></datetime-picker>
</form>
Github上鍊接:https://github.com/knobli/meetingApp
運行應用程序: 個NPM安裝-g涼亭喲一飲而盡發電機mobileangularui 涼亭安裝 一飲而盡建立 一飲而盡
@ pankajparkar該元素是一個包含標籤和輸入元素的div元素。 – knobli
請嘗試'$(元素).find('。datetime-picker')。datetimepicker'看起來像每次你正在初始化datepicker所有具有'datetime-picker'類的元素 –
@ pankajparkar謝謝你的作品,但它沒有解決問題 – knobli