0

I'm listing stories on an angular html page as follows:

<li class="myStories" ng-repeat="story in authors.currentAuthor.stories | orderBy: '-_id'">
       <!--  <span ng-if="checked" class="animate-if"> -->
        Title: {{ story.title }}<br>
        Genre: {{ story.genre }}
  <a ui-sref-active="active" ui-sref="storyEdit({ id: story._id })" 
       id="{{ story._id }}">Edit Story
  </a> 
</li>

The Angular docs state that "ng-if directive remove DOM element if expression return false" so I wondered whether it is possible/legitimate to delete an item using ng-if?

Hadi J
  • 16,989
  • 4
  • 36
  • 62
Andy83
  • 79
  • 9

1 Answers1

1

The item is only removed from DOM. It's still in your data representation. For visual things it is legitimate and most of the time better than ng-show see: When to favor ng-if vs. ng-show/ng-hide?

Community
  • 1
  • 1
trollr
  • 1,095
  • 12
  • 27
  • Thanks trollr, that helps - so if I understand correctly I could use it on the current (authorProfile) page to remove it from the list there but it would still appear elsewhere (eg an 'all stories' page) – Andy83 Apr 06 '16 at 10:11
  • Could you define `data representation` please? If you mean the scope that the `ngIf` creates then it is deleted and recreated right? – ste2425 Apr 06 '16 at 10:11
  • 1
    The data are still in authors.currentAuthor.stories, if we use the example above from Andy83. ng-if removes and creates the DOM element. That's right. – trollr Apr 06 '16 at 10:14