angularjs - Angular ng-repeat with polling data provider -
i reading angular now.
let's ng-repeat binding in effect, , child records appear <li> elements beneath <ul>.
now let's new objects pushed onto watched array (watched watchcollection) in model every 60 seconds polling data provider (i.e. existing data in array don't change).
will angular append new counterpart <li> elements <ul> or completely recreate <ul> when detects array has additional elements?
edit: @blackhole has asked, "why ask...?", i'll elaborate more complicated hypothetical matches pretty actual app, i'm thinking of rewriting learn angular.
imagine have fetch manifest immensely long freight train , display users contents of each freight car. don't want user wait , wait , wait, , see entire freight train manifest. instead, ask server list of car ids , fetch each car's manifest in turn, , in success callback, pop carid off array, , fetch next car's manifest, until array of car ids empty. expect ui add current car's manifest page immediately, next car's manifest being fetched.
after quick test, can confirm when pushing new items bound array, former dom elements not recreated.
to prove it, created simple array , bound ng-repeat, created jquery method changes dom elements, note when push new element array (using angular) elements changed using jquery method:
app.controller('mainctrl', function($scope) { $scope.items = []; $scope.pushitems = function(){ var newitem = {description: 'item description ' + $scope.items.length}; $scope.items.push(newitem); } $scope.newarray = function(){ var newarray = [{description: 'first item of new array'}] $scope.items = newarray; } $scope.reassign = function(){ var newarray = angular.copy($scope.items); $scope.items = newarray; } }); $( document ).ready(function() { $("#domchanger").click(function(){ $(".mylist li").html('changed'); }); }); here plunkr demonstration: http://plnkr.co/edit/2scx4zjjdorlqwgtivar?p=preview
Comments
Post a Comment