0

I want a way to display if something is not present then display something else.

so far I have this:

<span ng-if="likes.length = 0"> No hacks to display </span>

so if the length is zero then display this.

this code filters to order if present:

<md-list-item class="md-3-line hacks-hack"
    ng-repeat="hack in hacksCtrl.hacks | orderBy: likes.length : reverse | filter:searchText | filter:hacksCtrl.filterStatus"
    ng-click=hacksCtrl.goToHack(hack.id)>

not sure what i am missing, thanks

2 Answers 2

2

= operator assign a value to the variable on the left side of the expression.

Use === or == for comparison.

<span ng-if="likes.length === 0"> No hacks to display </span>

=== operator won't do the type conversion before the comparison while == does the type conversion before the comparison.

=== (Identity operator) is the correct way to compare if both the operands are of same type.

Here is minimal a working sample

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

6 Comments

ok that makes sense, but still wont render it even if the list of hacks disappear
@TheHurricane you might have another script error. See my updated answer which has a minimal working sample which solves your original question.
yours is displaying alongside though, i want it to appear when the list is blank
It is displaying that span when the likes is empty.
ok got ya. mine displays for about a second, then all the hacks appear, then i will search for one that is not there and then the message does not re appear. so how do you get it to display everytime rather than a one off which is what mine is doing for some reason
|
0

Have you tried using ng-show instead of ng-if? ng-if only renders on the page if that statement is true. And where you're using a filter, I would suggest trying ng-show where it is simple text and wouldn't really effect rendering time.

3 Comments

it appears initially, then the array gets populated, then i will search for something not in the array but the message does not pop back up
It appears, after looking at your example again, you're checking likes === 0 and should possibly be checking hacksCtrl.hacks. Or am I misunderstanding your code? Could you create a simple plunkr or something to give me a sample to go off of?
i am now doing this <div ng-show="hacksCtrl.hacks.length == 0"> No hacks to display </div>

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.