1

How to hide the checkbox with the text getting removed in the below picture :

Screen 1 :

When the page is loaded the screen would look like below :

enter image description here

Screen 2 :

When the checkbox is checked ,the text disappears but checkbox remains there.

enter image description here

Javascript Code:

function TodoCtrl($scope) {
  $scope.todos = [
    {text:'learn angular', done:true},
    {text:'build an angular app', done:false}];

  $scope.addTodo = function() {
    $scope.todos.push({text:$scope.todoText, done:false});
    $scope.todoText = '';
  };

  $scope.remaining = function() {
    var count = 0;
    angular.forEach($scope.todos, function(todo) {
      count += todo.done ? 0 : 1;
    });
    return count;
  };

  $scope.archive = function() {
    var oldTodos = $scope.todos;
    $scope.todos = [];
    angular.forEach(oldTodos, function(todo) {
      if (!todo.done) $scope.todos.push(todo);
    });
  };
}

FIDDLE LINK HERE

1
  • You might want to consider hiding the elements using ng-hide, instead of adding a class and hiding the element with a CSS style. Commented May 20, 2015 at 8:20

2 Answers 2

1

Check out this fiddle

 <li ng-repeat="todo in todos" class="done-{{todo.done}}">
    <input type="checkbox" ng-model="todo.done">
    <span >{{todo.text}}</span>
  </li>

You had to move the class to the whole list element to hide it, not only the text

Sign up to request clarification or add additional context in comments.

Comments

0

put the class="done-{{todo.done}}"

also on the checkbox

<input class="done-{{todo.done}}" type="checkbox" ng-model="todo.done">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.