在Angularjs中创建开始日期和结束日期的最佳方法是什么?我在下面的代码中使用了相同的控制器。最佳做法是为每个日期选择器创建一个单独的控制器吗?我的意图是有一个搜索按钮,它将从两个日期选择器中获取输入,然后进行一些后端处理。
我的HTML
<input type="text"
class="form-control"
datepicker-popup="{{format}}"
ng-model="startdt" is-open="opened"
datepicker-options="dateOptions"
ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="startopen($event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
我的Javascript
///////////// BEGIN Datepicker code
$scope.today = function () {
$scope.startdt = $filter('date')((new Date()), "dd-MMMM-yyyy");
$scope.enddt = $filter('date')((new Date()), "dd-MMMM-yyyy");
};
$scope.today();
$scope.clear = function () {
$scope.dt = null;
};
$scope.startopen = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.endopen = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];