AngularJS $mdToast 不隐藏
AngularJS $mdToast doesn't hide
我正在构建一个使用 AngularJS 和 Angular Material 前端的 Web 应用程序。我想使用 $mdToast 作为错误通知。
我的主应用程序控制器 (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);
});
我正在构建一个使用 AngularJS 和 Angular Material 前端的 Web 应用程序。我想使用 $mdToast 作为错误通知。
我的主应用程序控制器 (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);
});