简体   繁体   English

在angular2中使用window对象但是vscode“找不到名称'窗口'”

[英]Use window object in angular2 but vscode “Cannot find name 'window' ”

I wrote an angular2 app in Visual studio code. 我在Visual Studio代码中编写了一个angular2应用程序。 Recently, I updated Visual Studio Code to 1.10.2. 最近,我将Visual Studio Code更新为1.10.2。 But it has highlighted window as having an error. 但它突出显示window有错误。 When I checked it, I found that it says: 当我检查它时,我发现它说:

[ts] Cannot find name 'window'. [ts]找不到名字'窗口'。

My code is as follows: 我的代码如下:

saveCustomIndex(customIndex:any,indexName:string){
    window.localStorage.setItem(indexName,JSON.stringify(customIndex));
}

Screenshot 截图

问题截图

How can I deal with this? 我怎么处理这个? Thank you! 谢谢!

On tsconfig.json , make sure to have "dom" on your list of libraries. tsconfig.json ,确保在库列表中有"dom"

tsconfig.json should be looking more or less like this: tsconfig.json应该看起来或多或少像这样:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

Compiler options 编译器选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM