David Tunnell
David Tunnell

Reputation: 7542

Using ng-if with multiple conditions in HTML

I'm trying to add a button that only shows for particular index numbers:

            <tbody data-ng-repeat="(wholesalerIndex,wholesaler) in wholesalers">
                <tr>
                    <td>
                        <button ng-if="$index != 0 || $index != 3" class="btn btn-danger" data-ng-click="removeWholesaler(wholesaler, wholesalerIndex)">Up</button>
                        <button class="btn btn-danger" data-ng-click="removeWholesaler(wholesaler, wholesalerIndex)">Down</button>
                    </td>
                </tr>
            </tbody>

ng-if isn't working. It works fine when I have 1 condition ng-if="$index != 0", but when I try to add the OR (||) statement it stops working.

What am I doing wrong and how do I fix it?

Upvotes: 1

Views: 588

Answers (2)

Jonathan Brizio
Jonathan Brizio

Reputation: 1210

Just use ng-show it will work :)

<tbody data-ng-repeat="(wholesalerIndex,wholesaler) in wholesalers">
    <tr>
        <td>
            <button ng-show="$index != 0 || $index != 3" class="btn btn-danger" data-ng-click="removeWholesaler(wholesaler, wholesalerIndex)">Up</button>
            <button class="btn btn-danger" data-ng-click="removeWholesaler(wholesaler, wholesalerIndex)">Down</button>
        </td>
    </tr>
</tbody>

I hope that this helps.

Upvotes: 0

Paurian
Paurian

Reputation: 1402

My guess is the logic is off. Try logical and instead of logical or.

<button ng-if="$index != 0 && $index != 3" class="btn btn-danger" data-ng-click="removeWholesaler(wholesaler, wholesalerIndex)">Up</button>

Upvotes: 1

Related Questions