gpt4 book ai didi

javascript - 无法调用基本 ngAnimate 示例的函数

转载 作者:行者123 更新时间:2023-11-27 23:56:29 25 4
gpt4 key购买 nike

我正在尝试使用 ngAnimate 获得一个基本示例,我创建了一个 jsfiddle,其中包含来自 Angular 文档 ngAnimate 的代码:

JSFIDDLE

var myApp = angular.module('myApp',['ngAnimate']);

myApp.controller('MyCtrl', function($scope) {
$scope.name = 'Superhero';

$scope.items = ['A','B','C'];

}).animation('.slide', [function() {
return {
// make note that other events (like addClass/removeClass)
// have different function input parameters
enter: function(element, doneFn) {
console.log('enter');
// knows that the animation has concluded
},

move: function(element, doneFn) {
console.log('move');
},

leave: function(element, doneFn) {
console.log('leave');
}
}
}]);

我预计至少会调用 Enter 函数,我在这里缺少什么?

最佳答案

ngAnimate 不会在初始加载时触发。这是关于它的 Github 票证:https://github.com/angular/angular.js/issues/10536

但是,你的动画确实有效!如果将以下内容添加到 Controller :

$timeout(function(){ $scope.items.push('D'); }, 1000);

您将看到记录了'enter'。 (JSFiddle)

类似地,如果在超时时间内加载整个数组,它将记录每个项目。它只需要在 Angular 完成应用程序设置之后即可。

之前有一些技巧可以使初始加载动画正常工作,但这些看起来not to work anymore .

关于javascript - 无法调用基本 ngAnimate 示例的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32225555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com