小编pra*_*olu的帖子

TS2339:类型“元素”上不存在属性“样式”?

这是代码:

ngOnInit() {
const navSlide = () => {
  const burger = document.querySelector('.burger');
  const nav = document.querySelector('.nav-links');
  const navLinks = document.querySelectorAll('.nav-links li');
  burger.addEventListener('click', () => {
    nav.classList.toggle('nav-active');
  });
  navLinks.forEach((link, index) => {
  link.style.animation = `navLinkFade 0.5s ease forwards ${index / 7 + 0.3}s`;
   });
};
navSlide();
Run Code Online (Sandbox Code Playgroud)

}

编译时出现错误:

Property 'style' does not exist on type 'Element'.ts(2339)
Run Code Online (Sandbox Code Playgroud)

我该如何修复它?

javascript typescript angular

1
推荐指数
1
解决办法
8404
查看次数

标签 统计

angular ×1

javascript ×1

typescript ×1