0

I have an ng-repeat that contains a filter on one of the items in the repeated list. The filter works fine except when I add an item to the ng-repeated array. The ng-repeat looks something like this:

<div ng-repeat="post in posts">
    <div>{{post.created | formatTimestamp}}</div>
    <div>{{post.message}}</div>
</div> 

The formatTimestamp filter definitely works, and is probably too long to list here, so I'll omit it. The problem I'm having is that when a user makes a new post I unshift the new post in to the posts array. The post shows up as expected, but the formatTimestamp filter doesn't apply. When I refresh the page, then the filter does work. Something about unshifting the new post prevents the filter from applying. I tried using scope.$digest(), but that didn't solve the problem. The handling of the new post is inside a directive and looks like this:

// store the new post in the database, etc.
scope.posts.unshift(data);
scope.$digest(); // didn't have any effect

Any ideas on what I'm doing wrong?

Chris Paterson
  • 1,129
  • 5
  • 21
  • 31
  • Do you mean the original value of `post.created` is shown? – runTarm Aug 16 '14 at 17:08
  • I think we need a little more code. I can't reproduce the problem from what you've given us. I tried to reproduce it here, but it works fine: http://jsfiddle.net/markm/qothgzkg/ – Mark Aug 16 '14 at 17:28
  • The date is displayed, but it isn't run through the filter. The filter does work, however, when I refresh the page. – Chris Paterson Aug 16 '14 at 21:11

1 Answers1

0

if not wrong you want to print the list in reverse order (i.e. last entry on top)?
did you tried printing the list in reverse order as discussed here and use scope.posts.push(data) to add a new entry.

maybe a workaround but if you think unshift is a problem than you can give this a try.
for better debugging though I would prefer to see more of your code

Community
  • 1
  • 1
S4beR
  • 1,872
  • 1
  • 17
  • 33