angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

ng-repeat doesn't work when window resize

Open buihoanghai opened this issue 12 years ago • 3 comments

It may be a bug or me wrong something? Here's an example: Controller:

  self.arr = [{
            'n': 1
        }, {
            'n': 2
        }];
        self.add = function () {
            self.arr.push({
                'n': self.arr.length + 1
            });
        };
     var f = true;
   $(window).resize(function () {
            if (f) {
                f = false;
                setTimeout(function() {
                    {
                        self.add();
                    }
                }, 2000);
            }

        });

View:

    <p ng-repeat="it in vm.arr">{{it.n}}</p>
    <button ng-click="vm.add()">add</button>

when I resize window 'arr' is expanded but ng-repeat doesn't work. I click button ng-repeat it works and show all array

buihoanghai avatar May 12 '14 07:05 buihoanghai

Hi, this is actually working as expected. You need to call scope.$digest() or scope.$apply() in your event handler, in order for the view to update

caitp avatar May 12 '14 07:05 caitp

Thank you. It work :+1:

buihoanghai avatar May 12 '14 10:05 buihoanghai

I have an another issue :( ng-style can bind but it don't effect to style.

<div ng-style="{'left':'703px', 'top':'-11px'}" style="left: 703px; top: -11px;"></div>

when window resize:

<div ng-repeat="com in vm.comments" ng-style="{'left':'525px', 'top':'-11px'}" style="left: 703px; top: -11px;"></div>

buihoanghai avatar May 13 '14 02:05 buihoanghai