0

I have simple angular / html code where I have a table and on each <li> there is checkbox and some text

My code looks like:

            <li ng-repeat="task in tasks | filter:statusFilter track by $index" ng-class="{completed: todo.completed}" ng-cloak>
                <div class="view">
                    <input class="toggle" type="checkbox" ng-model="todo.completed" ng-click="changeStatus(task.id)">
                    <label ng-dblclick="editTodo(todo)">{{task.text}}</label>
                    <button class="destroy" ng-click="removeeTask(task)"></button>
                </div>
                <form ng-submit="doneEditing(todo)">
                    <input class="edit" ng-trim="false" ng-model="todo.title" ng-blur="doneEditing(todo)" todo-escape="revertEditing(todo)" todo-focus="todo == editedTodo">
                </form>
            </li>

What this code do is:

  1. When user click CHECKBOX it call ng-click and update "active" in database
  2. Add "completed" which basicly change style of that <li> a bit

All data comes from some webservices and each task I have contains this information:

  • id
  • priority
  • text
  • active

    My problem is that when I refresh the page I don't have any filter which add completed to all task which active is 0

    Can someone help me how to make some if / else condition for this purpose?

  • Andurit
    • 5,612
    • 14
    • 69
    • 121
    • What are you trying to make conditional? just bind it to a variable on the scope or just use an inline ternary – johnny 5 Oct 15 '15 at 14:52
    • Possible duplicate of [if else statement in AngularJS templates](https://stackoverflow.com/questions/15810278/if-else-statement-in-angularjs-templates) – Liam Nov 20 '17 at 14:21

    1 Answers1

    1

    Use following:

    ng-class="{{completed : todo.active == 0}}"
    

    In this case li-Tag gets class completed if todo.active equals 0

    David
    • 153
    • 7
    • Hey @David, thanks this actualy work really well. But right now when I click checkbox nothing is going to happen :) becuase it is connected with todo.connected. So is there some way how to maybe just press all checkbox on clicked ? – Andurit Oct 15 '15 at 14:58
    • Where ist todo.connected coming from? Its not in the information you posted. Could you please explain more detail? – David Oct 15 '15 at 15:07