Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/sb-date-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

angular.module('sbDateSelect', [])

.directive('sbDateSelect', [function () {
.run(['$templateCache', function ($templateCache) {

var template = [
'<div class="sb-date-select">',
'<select class="sb-date-select-day sb-date-select-select" ng-class="selectClass" ng-model="val.date", ng-options="d for d in dates track by d">',
'<select class="sb-date-select-day sb-date-select-select" ng-class="selectClass" ng-model="val.date" ng-options="d for d in dates track by d">',
'<option value disabled selected>Day</option>',
'</select>',
'<select class="sb-date-select-month sb-date-select-select" ng-class="selectClass" ng-model="val.month", ng-options="m.value as m.name for m in months">',
'<select class="sb-date-select-month sb-date-select-select" ng-class="selectClass" ng-model="val.month" ng-options="m.value as m.name for m in months">',
'<option value disabled>Month</option>',
'</select>',
'<select class="sb-date-select-year sb-date-select-select" ng-class="selectClass" ng-model="val.year" ng-options="y for y in years">',
Expand All @@ -18,10 +18,18 @@ angular.module('sbDateSelect', [])
'</div>'
];

$templateCache.put('sb-date-select.html', template.join(''));

}])

.directive('sbDateSelect', [function () {

return {
restrict: 'A',
replace: true,
template: template.join(''),
templateUrl: function ($element, $attrs) {
return $attrs.templateUrl || 'sb-date-select.html';
},
require: 'ngModel',
scope: {
selectClass: '@sbSelectClass'
Expand Down Expand Up @@ -87,7 +95,7 @@ angular.module('sbDateSelect', [])

if (scope.val.year && scope.val.month && max.isSame([scope.val.year, scope.val.month-1], 'month')) {
maxDate = max.date();
} else if (scope.val.year && scope.val.month) {
} else if (scope.val.year && scope.val.month) {
maxDate = moment([scope.val.year, scope.val.month-1]).daysInMonth();
} else {
maxDate = 31;
Expand Down Expand Up @@ -117,4 +125,3 @@ angular.module('sbDateSelect', [])
}
};
}]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need remove last empty line