V
V
v-orlov2016-08-19 11:56:25
Angular
v-orlov, 2016-08-19 11:56:25

How to run the toggleClass method using Angular js if the string has a class?

My table:

<table>
  <tr class="imp" toggle-class="active">
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr class="imp" toggle-class="active">
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>

My toggle-class directive:
angular.module("app")
.directive('toggleClass', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
            element.bind('click', function() {
                element.toggleClass(attrs.toggleClass);
            });
        }
    };
});

My styles that fill and uncolor the line I clicked on.
.active {background: blue;}
I'm doing it wrong, because the lines will be output via ng-repeat, and I need a normal condition to fill the lines, which will be assigned the .imp class by another condition. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sasha, 2016-08-26
@madmages

<div class="{{expression=='one'?'active_class':''}}" ng-click="expression='one'"></div>
<div class="{{expression=='two'?'active_class':''}}" ng-click="expression='two'"></div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question