我制作了日期时间选择器指令
adocsModule.directive('dateTimePicker', ['$timeout', function ($timeout) {
return {
link: function (scope, element, attrs, ctrl) {
$timeout(function () {
element.datetimepicker({
//language: 'fr',
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 0,
showMeridian: 1
});
}, 10);
scope.$apply();
}
}
}]);
我在html中使用了这个指令,它的工作正常,但问题是当我按日期时间选择器设置值时,它永远不会更新ng-model属性。我在控制器中得到permision.dateFrom为空。请帮帮我
<div ng-show="permission.showDuration">
<div class="form-group margin-left-20px margin-top-5px">
<input type="text" date-time-picker class="form-control font-11px input-style1" placeholder="Select date from" ng-model="permission.fromdate" >
</div>
<div class="form-group margin-left-20px margin-top-5px">
<input type="text" date-time-picker class="form-control font-11px input-style1" placeholder="Select date from" ng-model="permission.todate">
</div>
</div>
答案 0 :(得分:1)
我曾经使用过datetime,这就是我如何修复
.on('changeDate', function (ev) {
$parse(attrs.ngModel).assign(scope, ev.date);
scope.$apply();
});
您需要解析属性,然后将其值分配给模型,并应用更改