属性“哈希”在类型“ HTMLElement”上不存在

时间:2019-05-27 12:52:17

标签: jquery angular angular7

我正在使用angular7。我需要制作单页网站,所以我在菜单链接中提供了该部分的ID名称。因此,当您单击链接时,它将带您到页面的相应部分。我为此使用了以下jQuery代码。

    $(".navbar .nav-link").on('click', function(event) {
        var hash = this.hash;
        if (this.hash !== "") {
            event.preventDefault();
            $('html, body').animate({
                scrollTop: $(hash).offset().top
            }, 1000, function(){
                window.location.hash = hash;
            });
        } 
    }); 

它以正常的html格式工作,但是当我移入有角度的框架时,它显示以下错误。

  

src / app / app.component.ts(20,13):错误TS2339:类型“ HTMLElement”上不存在属性“哈希”。

0 个答案:

没有答案