如果date在$ scope中,则在AngularJS datepicker按钮上自定义css-class

时间:2015-11-10 10:35:55

标签: css angularjs date datepicker

在我的AngularJS应用中,我有$scope这样的

controller.js

$scope.takeovers = {
    "_id":"5640989531622c5c28fd41c7",
    "activationDate":[{
        "start":"2015-10-31T23:00:00.000Z",
        "end":"2015-11-05T23:00:00.000Z",
        "_id":"5640989531622c5c28fd41cc"
    }],
    "_id":"5640a14a1a743d001a3a1c94",
    "activationDate":[{
        "start":"2015-11-07T23:00:00.000Z",
        "end":"2015-11-05T23:00:00.000Z",
        "_id":"2015-11-12T23:00:00.000Z"
    }]
}

在视图中,我使用以下选项生成datepicker

index.jade

datepicker( ng-model="upcoming" 
            show-weeks="false" 
            ng-click='selectTakeover(upcoming)' 
            custom-class='getDayClass(date)')

现在我想让getDayClass(date)函数将date$scope.activationDate startend进行比较,如果date介于两者之间startend返回名为highlight-current-date

的css类
$scope.getDayClass = function(date) {

    //The date object contains ISO-date from datepicker option "custom-class"
    //Here I want to compare date with $scope.activationDate to see if date is 
    //between $scope.activationDate.start and $scope.activationDate.end.

    //I know I need to re-format the dates to be able to match them. 
    //This can be done using $filter('date')(date, 'yyyy-MM-dd:hh:mm')
    // if match then var result = 'highlight-current-date';

    return result;
}

我试图将date传递给angular.forEach函数,该函数遍历$scope.takeovers但我无法返回工作类,因为每次都会覆盖结果{{1} 1}}迭代,我无法打破它。

0 个答案:

没有答案