0

I have an angularjs app. I have a checkbox in my html :

<input ng-true-value="Paused" ng-model="paused" type="checkbox">Show Paused

When I click this checkbox it should only display the elements having the class='paused'. for eg let's say this is my view:

<span class="paused">1</span>
<span class="notpaused">2</span>
<span class="notpaused">3</span>

So when I click on Show Paused I want that only the <span> with class="paused" be visible in the view. other elements should be hidden from the view. I know how to use filters in angularjs but I'm not able to figure out how to do it when we have to filter by class name. Any suggestions on how can I do it?

2 Answers 2

1

If you are changing the value of pause variable using your ng-model, it will give result as true or false.

so, you can use it like

    <span ng-if="paused">1</span>
    <span ng-if="!paused">2</span>
    <span ng-if="!paused">3</span>

or with your logic.

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

Comments

1

I got it to work like this :

<input ng-true-value="'Paused'"  ng-false-value="''" ng-model="paused" 
type="checkbox">Show Paused

<div ng-repeat="x in users|filter:paused" >

//tip for beginners > ng-class="{'paused': x.stat == 'Paused',
'notpaused': x.stat == 'notPaused'}" assigns the class paused/notpaused 
and {{x.id}} prints the value 1.

<span class="paused">1</span> 

<span class="notpaused">2</span>
<span class="notpaused">3</span>
</div>

Earlier when I used to set ng-true-value="Paused" it would always return true hence my filter was not working as the value of ng-model="paused" would evaluate to true/false instead of Paused when the checkbox is checked. But when I included the single quotes like this : ng-true-value="'Paused'" , my filter is now working perfectly. Hope this helps somebody

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.