属性'hash'在'HTMLElement'类型上不存在

问题描述 投票:0回答:1

我正在使用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'上不存在属性'hash'。

jquery angular angular7
1个回答
0
投票

我有错误的错误。有人告诉我如何使用箭头功能解决此问题吗?我是Angular的新手。预先感谢!

© www.soinside.com 2019 - 2024. All rights reserved.