gpt4 book ai didi

javascript - AngularJS $mdToast 不隐藏

转载 作者:行者123 更新时间:2023-11-30 00:06:36 25 4
gpt4 key购买 nike

我正在构建一个使用 AngularJS 和 Angular Material 前端的 Web 应用程序。我想使用 $mdToast 作为错误通知。

我的主应用程序 Controller (AppCtrl) 中有以下代码:

$rootScope.$on('httpError', function (event, errorMessage) {
$mdToast.show(
$mdToast.simple()
.textContent(errorMessage.message)
.position('top right')
.hideDelay(3000)
);
});

但是在另一个 $scope 中触发错误时,在 hideDelay 过期后,toast 不会以某种方式隐藏。

有人知道如何解决这个问题吗?

最佳答案

您的代码对我来说似乎工作正常。我没有尝试从另一个范围广播事件。您可以尝试使用 $timeout 来隐藏对话框,而不是像我在 this Plunker 中那样使用 hideDelay() 函数。 .

更新后的代码看起来像这样:

$rootScope.$on('httpError', function (event, errorMessage) {
$mdToast.show(
$mdToast.simple()
.textContent(errorMessage.message)
.position('top right')
);
$timeout(function() {
$mdToast.hide();
}, 3000);
});

关于javascript - AngularJS $mdToast 不隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38275277/

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