AngularJS 只有 ng-repeat 动画中的第一个元素 [英] AngularJS only first element in ng-repeat animates

查看:25
本文介绍了AngularJS 只有 ng-repeat 动画中的第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,使用下面的代码,ngRepeat 只对第一项进行动画处理,并立即显示其余部分.一旦 scope.categories 项目更新,ng-repeat 就会在模板中触发.

For some reason using the code below, ngRepeat only animates the first item and displays the rest instantly. As soon as the scope.categories item is updated the ng-repeat is triggered in the template.

dataSource.getCategories()
    .then(function(categories) {
        $scope.categories = categories;
    }, function(message) {
        dataSource.setActivity(false, message);
    });

但如果我将代码更改为下面的代码并在页面中添加 Start</a> ,它就可以工作了.是的,我已经尝试过 $timeout,甚至长达 5 秒,但它并没有改变这种情况.

But if I change the code to the one below and add <a ng-click="start()">Start</a> in the page, it works. Yes, I have tried $timeout, even up to 5 seconds and it does not change the situation.

dataSource.getCategories()
    .then(function(categories) {
        $scope.start = function() {
            $scope.categories = categories;
        }

    }, function(message) {
        dataSource.setActivity(false, message);
    });

有没有人有办法解决这个问题?

Does anyone have a solution to this?

推荐答案

我用 AngularJS 1.2.9 尝试了你的 CSS 并得到了相同的结果.然而,它适用于 1.2.13.1.2.* 分支中的 ngAnimate 模块发生了很多变化,所以没有深入研究这个问题,我猜测这是一个已经修复的错误.

I tried your CSS with AngularJS 1.2.9 and got the same result. It works with 1.2.13 however. There have been so many changes to the ngAnimate module in the 1.2.*-branches so without digging deeper into the matter my guess is it's a bug that has since been fixed.

演示 - 1.2.9 不工作:http://plnkr.co/edit/WvK2DDB6wTUkjx4Ah2bs?p=preview

演示 - 1.2.13 工作:http://plnkr.co/edit/50UdTAKAsua85hyLc1O6?p=preview

这篇关于AngularJS 只有 ng-repeat 动画中的第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆