2

I'm trying to display a series of image on the screen but hide or not show the one with a specific image name, but so some reason it is either hiding all images or showing just one.

Here is my code, any help is appreciated.

<div ng-repeat="x in documents" ng-if="x.document_name=='leftover.png'" ng-show="not_admin">             
    <img src="{{ x.image }}" width="30" height="30"> 
    <p><b>{{ x.document_name }}</b></p>          
</div>

I want to hide just one div if the image is 'leftover.png' and not_admin is true which is already set to true in my controller.

Update

I should have been a lot clearer, what I want is to show all the images if the user is an admin, but hide just the 'leftover.png' otherwise.

So, if the logged in user is not an admin, they can see all the images except 'leftover.png', but when an admin logs in they can see all the images.

I hope this makes more sense.

2 Answers 2

1

You can combine both condition in single ng-if

<div ng-repeat="x in documents" ng-if="!x.document_name=='leftover.png' && !not_admin">             
    <img src="{{ x.image }}" width="30" height="30"> 
    <p><b>{{ x.document_name }}</b></p>          
</div>
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks, your suggestion hides all the images - nothing shows on the screen. I want to hide just one image if they are not an admin...that's the image with the name 'leftover.png'
try now i think it should
did it fix the issue?
Sorry, it did not work - still hiding the images. Hmm :(
I think you want !(x.document_name=='leftover.png' && not_admin) or !x.document_name=='leftover.png' || !not_admin for what you're trying to do. Display all images except lefover, unless not_admin is false.
|
0

Why you are using an unnecessary condition :

ng-show="not_admin" 

if it (not_admin) is true for all the cases and required. Try merging both the condition like this :

ng-if="x.document_name != 'leftover.png' && not_admin"

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.