gpt4 book ai didi

javascript - 没有 jquery 的 Angular $animate.addClass 回调

转载 作者:行者123 更新时间:2023-11-28 00:31:39 25 4
gpt4 key购买 nike

我的 Angular 项目中包含了 jquery,并且以下代码运行良好

scope.$watch('showWhen', function(newValue, oldValue) {
if (newValue) {
$animate.removeClass(element, 'ng-hide', scope.afterShow);
}
if (!newValue) {
$animate.addClass(element, 'ng-hide', scope.afterHide);
}
});

现在我已经删除了jquery,回调函数似乎没有被调用。我想这是因为它是一个 jquery 函数。我在 $animate 文档中看不到任何说明您可以传递回调函数的内容。

有人知道如何仅使用 Angular 来做到这一点吗?

最佳答案

它没有回调,但它返回一个 promise 。你可以这样做:

$animate.removeClass(element, 'ng-hide').then(function() {
$scope.afterShow();
});

关于javascript - 没有 jquery 的 Angular $animate.addClass 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28924798/

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