admin管理员组文章数量:1333451
I wrote an angular2
app in Visual studio code. Recently, I updated Visual Studio Code to 1.10.2. But it has highlighted window
as having an error. When I checked it, I found that it says:
[ts] Cannot find name 'window'.
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!
I wrote an angular2
app in Visual studio code. Recently, I updated Visual Studio Code to 1.10.2. But it has highlighted window
as having an error. When I checked it, I found that it says:
[ts] Cannot find name 'window'.
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!
Share Improve this question edited Mar 15, 2017 at 10:19 Angelos Chalaris 6,7078 gold badges53 silver badges80 bronze badges asked Mar 12, 2017 at 8:07 yilihjyyilihjy 731 silver badge4 bronze badges 1-
Try to add options
"lib": [ "es2015", "dom" ],
in your tsconfig.json – yurzui Commented Mar 12, 2017 at 8:14
1 Answer
Reset to default 9On tsconfig.json
, make sure to have "dom"
on your list of libraries.
tsconfig.json
should be looking more or less like this:
{
"pileOnSave": false,
"pilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "monjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
]
}
}
Compiler options
版权声明:本文标题:javascript - Use window object in angular2 but vscode "Cannot find name 'window' " - Stack Ove 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742350469a2458388.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论