Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngIf and array values #7708

Closed
thorn0 opened this issue Jun 5, 2014 · 3 comments
Closed

ngIf and array values #7708

thorn0 opened this issue Jun 5, 2014 · 3 comments

Comments

@thorn0
Copy link
Contributor

thorn0 commented Jun 5, 2014

Consider the following code:

  <table ng-if="items" border='10'>
    <tr ng-repeat="item in items track by item.id">
      ...
      <td><a ng-click="removeFromList(item)">Remove</a>
      </td>
    </tr>
  </table>

removeFromList modifies the existing array, so the array is always the same object. After the user deletes all the items, we might expect the table will be removed from the DOM because of ngIf and the fact that empty arrays are considered falsy in ngIf, ngShow, etc. However, it doesn't happen.

A plunk to play with: http://plnkr.co/edit/FVM0k2K3t4HutA4pZDk4?p=preview

@joshkurz
Copy link
Contributor

joshkurz commented Jun 5, 2014

why wouldn't you just check for the length to equal 0, if that is your requirement? http://plnkr.co/edit/ritjXTukVNhFAHngpwal?p=preview

@thorn0
Copy link
Contributor Author

thorn0 commented Jun 5, 2014

@joshkurz Because there's a certain convention about truthiness of expressions that I thought I could rely on.

@lgalfaso
Copy link
Contributor

lgalfaso commented Jun 5, 2014

This looks like a duplicate of #3969 (and many other), there is a PR at #4005 that fixes this issue

@lgalfaso lgalfaso closed this as completed Jun 5, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants