我一辈子都无法让变量“开始”和“结束”返回到我在控制器中的函数。
l() == 控制台.log()
我试图把这个:http ://www.dangrossman.info/2012/08/20/a-date-range-picker-for-twitter-bootstrap/
对此的指令:https ://github.com/clouddueling/angularjs-common
控制器.js
ontrollers.controller('PatientsCtrl', function($scope, $http, $location, $cookies, Popup, Value, Users, User, System){
$scope.loadUserSystems = function(start, end) {
l(start);
l(end);
return;
$scope.activeUser = this.user ? this.user : $scope.activeUser;
User.systems($scope.activeUser.id, start, end).success(function(data){
$scope.activeSystems = data.systems;
});
}
$scope.dateRangeOptions = {
ranges: {
'Today': [new Date(), new Date()],
'Yesterday': [moment().subtract('days', 1), moment().subtract('days', 1)],
'Last 7 Days': [moment().subtract('days', 6), new Date()],
'Last 30 Days': [moment().subtract('days', 29), new Date()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
},
format: 'MM/DD/YYYY',
separator: ' to ',
startDate: moment().subtract('days', 29),
endDate: new Date(),
minDate: '01/01/2012',
maxDate: '12/31/2013',
locale: {
applyLabel: 'Submit',
fromLabel: 'From',
toLabel: 'To',
customRangeLabel: 'Custom Range',
daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr','Sa'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
firstDay: 1
},
showWeekNumbers: true,
buttonClasses: ['btn-danger'],
dateLimit: false
}
});
部分.html
<div class='btn'>
<i class='icon-calendar'></i>
<span
date-range-picker
options='dateRangeOptions'
change='loadUserSystems(start, end)'></span>
</div>
指令.js
directives.directive('dateRangePicker', function ($parse) {
return {
restrict: 'A',
scope: {
options: '=',
},
template: "<span></span> <b class='caret'></b>",
link: function (scope, element, attr) {
$(element).daterangepicker(scope.options, function(start, end){
$(element).find('span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
// Retrieve the callback function
var fn = $parse(attr.change);
scope.$apply(function () {
fn(scope, { start: start, end: end });
});
});
$(element).find('span').html(moment().format('MMMM D, YYYY') + ' - ' + moment().format('MMMM D, YYYY'));
}
};
});