小编Kat*_*edy的帖子

错误 TS2339:JavaScript 到 Typescript 错误


src/app/dashboard.component.ts(49,15) 中的错误:错误 TS2339:类型“Element”上不存在属性“style”。src/app/dashboard.component.ts(50,16):错误 TS2339:类型“EventTarget”上不存在属性“textContent”。


这是一个 javascript 函数,但上面是我尝试在打字稿中使用它时遇到的错误。我尝试将 var 更改为 let 并添加 . 还有其他建议吗?谢谢。

仪表板.ts

var w = document.getElementById('wrapper');
var button = document.getElementById('randomize');
var image = w.children; // inner elements, your quotes divs

// a function to hide all divs
var hideDivs = function(divs) {
  for (var div of divs) {
    div.style.display = 'none';
  }
}

hideDivs(image); // hide all initially

// on click
button.addEventListener('click', function(event) {
  var rnd = Math.floor(Math.random() * image.length); // get random index
  hideDivs(image); // hide all …
Run Code Online (Sandbox Code Playgroud)

javascript syntax-error typescript angular

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

标签 统计

angular ×1

javascript ×1

syntax-error ×1

typescript ×1