$timeout 立即运行而不是等待超时

$timeout runs instantly instead of waiting for the timeout

我正在开发一项显示通知并在特定时间后将其隐藏的服务,但是 $timeout 运行s 中的代码立即生效,我知道显示部分有效,因为当我 运行 它逐行我可以看到它,但是一旦我转到超时行它就被隐藏了,本节中的超时设置为 10 秒。下面是 $timeout 部分

    $timeout(() => {
        var domElement = angular.element(
            document.querySelector('#toast-notification')
        );
        domElement.removeClass('show');
    }, data.eventDuration);

请注意 data.eventDuration 必须 10000 10 秒,因为 $timeout 以毫秒计算。

var data = {};
data.eventDuration = 10000;
// now your function should be called after 10 seconds.

$timeout(() => {
    var domElement = angular.element(
        document.querySelector('#toast-notification')
    );
    domElement.removeClass('show');
}, data.eventDuration);