You should be able to wrap _refreshView in a new compilation function that wraps the function of the old link if you use a decorator. In your ctrl._refreshView shell ctrl._refreshView you can do something like:
directive.compile = function() { return function(scope, element, attrs, ctrl) { link.apply(this, arguments); var _refreshView = ctrl._refreshView; ctrl._refreshView = function() { _refreshView.apply(this, arguments); removeAnySecondaryOnlyRows(scope.rows); }; removeAnySecondaryOnlyRows(scope.rows); }; };
and
//Remove any rows that contain only 'secondary' dates (those from other months) function removeAnySecondaryOnlyRows(rows) { for (var i = 0; i < rows.length; i++) { var row = rows[i], areAllSecondary = false; //check the first and the last cell .secondary property areAllSecondary = row[0].secondary && row[(row.length - 1)].secondary; if (areAllSecondary) { rows.splice(i, 1); i--; } } }
And all together, as a functional fragment, including a custom template and some css to hide the "secondary" days (those that were from another month):
(function() { "use strict"; angular.module('myApp', ['ui.bootstrap']) .config(['$provide', Decorate]) .controller("MainController", ['$scope', MainController]); function Decorate($provide) {
.datepicker .invis { visibility: hidden; }
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.min.js"></script> <div ng-app="myApp" ng-controller="MainController"> <script id="common/directives/uiBootstrapDatepickerDay.tpl.html" type="text/ng-template"> <table role="grid" aria-labelledby="{{uniqueId}}-title" aria-activedescendant="{{activeDateId}}"> <thead> <tr> <th> <button type="button" class="btn btn-default btn-sm pull-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i> </button> </th> <th colspan="{{5 + showWeeks}}"> <button id="{{uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1" style="width:100%;"><strong>{{title}}</strong> </button> </th> <th> <button type="button" class="btn btn-default btn-sm pull-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i> </button> </th> </tr> <tr> <th ng-if="showWeeks" class="text-center"></th> <th ng-repeat="label in labels track by $index" class="text-center"><small aria-label="{{label.full}}">{{label.abbr}}</small> </th> </tr> </thead> <tbody> <tr ng-repeat="row in rows track by $index"> <td ng-if="showWeeks" class="text-center h6"><em>{{ weekNumbers[$index] }}</em> </td> <td ng-repeat="dt in row track by dt.date" class="text-center" role="gridcell" id="{{dt.uid}}" ng-class="dt.customClass"> <button type="button" style="min-width:100%;" class="btn btn-default btn-sm" ng-class="{'btn-info': dt.selected, active: isActive(dt), 'invis': dt.secondary}" ng-click="select(dt.date)" ng-disabled="dt.disabled" tabindex="-1"><span ng-class="{'text-muted': dt.secondary, 'text-info': dt.current}">{{dt.label}}</span> </button> </td> </tr> </tbody> </table> </script> <div> <strong>Selected date:</strong> {{dt.toDateString()}} </div> <div style="display:inline-block; min-height:290px;"> <div datepicker ng-model="dt" class="well well-sm datepicker"></div> </div> </div>
JcT Jul 23 '15 at 8:11 2015-07-23 08:11
source share