我有daterange的指令代码,但无法实现此指令的ngmodel。
它不显示其余日期范围的值。但是它将发送到休息日期范围值。你能告诉我如何编写该指令的ngmodel吗?
html代码:
<input type="text" daterangepicker class="form-control myCalendar ng-pristine ng-valid ng-touched" ng-model="data.dateRange">
js代码:
.directive('daterangepicker', function($rootScope, $parse) {
return {
restrict: "A",
require: 'ngModel',
scope: false,
link: function($scope, $element, attrs){
var ngModel = $parse(attrs.ngModel);
$element.daterangepicker({}
}, function(startDate, endDate) {
$scope.date = {startDate: startDate, endDate: endDate};
$scope.$apply();
});
$scope.$watch(ngModel, function (daterange) {
$($element).daterangepicker("setStartDate", daterange.substr(0, 10));
$($element).daterangepicker("setEndDate", daterange.substr(13, daterange.length));
});
}
}
})