Search code examples
angularjsng-class

Angularjs ng-class expression contains substring compared with current day


As you can see in the following code, I have a table, filled with various rows by ng-repeat and a JSON.

<tbody>
    <tr ng-repeat="roll in filtering(JSON) | orderBy:[sortType,'Cutoff']:sortReverse | filter:q as results" ng-class="{ 'danger': roll.Status == 'Running', 'success': roll.Status == 'Done', 'strike': roll.Days == 'MON'}" ng-if="roll.Group == groupType || groupType == 'yes'">
        <td>{{ roll.Status }}</td>
        <td>...</td>
    </tr>
 </tbody>

One row contains the variable 'Days' which has occurrences like f.e. MON for Monday or MONTUEWED for Monday till Wednesday or TUETHUFRI for Tuesday and Thursday till Friday.

I want to use the ng-class element (as can be seen above and in a snip below):

'strike': roll.Days == 'MON'

to check if my Days String (in roll.Days) for each row contains the current day (if possible something like Format(Now) to MON or TUE etc.) and apply the 'strike' css (for Information purpose: the row will then change to italic text and the background will be colored grey)

Any suggestions?

Kind regards, Martin


Solution

  • With help of the commentators I found a solution:

    http://jsfiddle.net/ARK5q/298/

    ng-repeat="jobSet in dashboard.currentWork" 
        ng-class="{'approved': jobSet.indexOf(selectedForApproval) >= 0}"
    

    Whereas the App Controller must be like:

    var app = angular.module("DemoApp", [])

    app.controller("DashboardCtrl", function($scope) {
    $scope.dashboard = {
        currentWork: [
            'MON',
            'MONTUE',
            'MONTUE',
            'MONTUEFRI',
            'TUEFRI',
            'TUE',
            'WED',
            'WED',
        ]
    };
        $scope.selectedForApproval = ['TUE'];
    });