Angular ng-show not working

178 Views Asked by At

I have a button in a directive that I only want to appear on the last object in the array. The ng-show evaluates an expression on the controller.

<button class="btn btn-danger button-xs tsid-btn-sch-pad
    glyphicon glyphicon-remove"
            type="submit" ng-click=""
            ng-show="{{$index == sc.schedule.length - 1}}"></button>

The expression is being correctly evaluated in the browser, but the button is displaying anyway.

enter image description here

So the difference between the highlighted row and the one above where the delete button is not displaying is that ng-hide was added to the class attribute of the row above and it has not been added to the row that is displaying the delete button incorrectly. But I don't know why that update isn't taking place since the ng-show expression is being updated.

1

There are 1 best solutions below

7
On

Try using the $last variable

<button class="btn btn-danger button-xs tsid-btn-sch-pad
    glyphicon glyphicon-remove"
            type="submit" ng-click=""
            ng-show="$last"></button>

http://plnkr.co/edit/Sf6Xw7YjPlfUuqyHIWng?p=preview