how to reload ng-repeat after list.push

29,811 views
Skip to first unread message

Patrik Votoček

unread,
Apr 4, 2012, 1:04:53 PM4/4/12
to ang...@googlegroups.com
Hi all,

is it possible reload (re-render) ng-repeat list items if I push another item to list (array)?

Peter Bacon Darwin

unread,
Apr 4, 2012, 1:09:41 PM4/4/12
to ang...@googlegroups.com
Welcome to the beauty of angular:  It automatically re-renders itself when the underlying array is changed.
Pete

On 4 April 2012 18:04, Patrik Votoček <pat...@votocek.cz> wrote:
Hi all,

is it possible reload (re-render) ng-repeat list items if I push another item to list (array)?

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/JcZeAUaCY2sJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Patrik Votoček

unread,
Apr 4, 2012, 1:50:17 PM4/4/12
to ang...@googlegroups.com
I'm using Socket.IO and this demo doesn't work http://jsfiddle.net/fqnKt/3/ 

Dne středa, 4. dubna 2012 19:09:41 UTC+2 Peter Bacon Darwin napsal(a):
Welcome to the beauty of angular:  It automatically re-renders itself when the underlying array is changed.
Pete

On 4 April 2012 18:04, Patrik Votoček <pat...@votocek.cz> wrote:
Hi all,

is it possible reload (re-render) ng-repeat list items if I push another item to list (array)?

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/JcZeAUaCY2sJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

Misko Hevery

unread,
Apr 4, 2012, 3:39:38 PM4/4/12
to ang...@googlegroups.com
Try this: http://jsfiddle.net/mhevery/fqnKt/4/
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/Jz7IGLcYpsMJ.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.

Patrik Votoček

unread,
Apr 4, 2012, 4:00:53 PM4/4/12
to ang...@googlegroups.com
awesome thanks

Dne středa, 4. dubna 2012 21:39:38 UTC+2 Misko Hevery napsal(a):

Silvio Troia

unread,
Mar 20, 2014, 5:36:30 AM3/20/14
to ang...@googlegroups.com
Is't possible to re-render a ng-repeat list item to applicate a filter?

if i push a item, angular put it as last element, without order it.

<div ng-repeat="item in items  | orderBy:'diffDay'  | groupBy:['diffDay'] | filter:filterDate(item)">

and in controller 

Publishing.save({}, function(item) {
            $scope.items.push(item);
          }); 

Lorenzo Bugiani

unread,
Mar 20, 2014, 7:33:09 AM3/20/14
to ang...@googlegroups.com
I haven't understand: what it the problem?
Every time items change, it will be re evaluated in ng-repeat.....


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.

To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Silvio Troia

unread,
Mar 20, 2014, 7:58:31 AM3/20/14
to ang...@googlegroups.com
in my code angular put item as last elements

it is.
my controller
 $scope.init = function(){
          Publishing.query({type:'S'}, function(items) {
            $scope. items = items;
            drawCalendar(items);
          });
};

this is a view 
<div ng-repeat="item in items  | orderBy:'diffDay'  | groupBy:['diffDay'] | filter:filterDate(item)">
  <h2 ng-show="item.group_by_CHANGED">{{item.displayGroupDay}}</h2>
    <ul>
      <li>
          {{item.nomePagina}}
          <img src="{{item.imageUrl}}"/>
          {{item.text}}
          <br/>
          {{item.data}}
      </li>
    </ul>
</div>

and this is a filter 

angular.module('myApp')
  .filter('groupBy', function ($parse) {
    return function (list, group_by) {
        var filtered = [];
        var prev_item = null;
        var group_changed = false;
        // this is a new field which is added to each item where we append "_CHANGED"
        // to indicate a field change in the list
        //was var new_field = group_by + '_CHANGED'; - JB 12/17/2013
        var new_field = 'group_by_CHANGED';
        // loop through each item in the list
        angular.forEach(list, function (item) {
            group_changed = false;
            // if not the first item
            if (prev_item !== null) {
                // check if any of the group by field changed
                
                //force group_by into Array
                group_by = angular.isArray(group_by) ? group_by : [group_by]; 
                
                //check each group by parameter
                for (var i = 0, len = group_by.length; i < len; i++) {
                    if ($parse(group_by[i])(prev_item) !== $parse(group_by[i])(item)) {
                        group_changed = true;
                    }
                }
                
            }// otherwise we have the first item in the list which is new
            else {
                group_changed = true;
            }
            if (group_changed) {
                item[new_field] = true;
            } else {
                item[new_field] = false;
            }
            filtered.push(item);
            prev_item = item;
        });
        return filtered;
    };
  }); 
 

Are there some error?

Birol Köklü

unread,
Nov 30, 2014, 6:38:47 PM11/30/14
to ang...@googlegroups.com
Thank you=)

4 Nisan 2012 Çarşamba 20:09:41 UTC+3 tarihinde Pete Bacon Darwin yazdı:
Reply all
Reply to author
Forward
0 new messages