简体   繁体   English

HTML linter 中的 Microsoft VS Code 和 Angular 2 标签

[英]Microsoft VS Code and Angular 2 tags in HTML linter

I just started using Angular 2 in VSCode.我刚开始在 VSCode 中使用 Angular 2。 Using the Angular.io "Tour of Heroes" as an example, the built-in HTML linter does not recognize the Angular 2 directives in the HTML tags, such as *ng-if or (click) , as you can see in this screen shot:以 Angular.io "Tour of Heroes" 为例,内置 HTML linter 无法识别 HTML 标签中的 Angular 2 指令,例如*ng-if(click) ,如您在此屏幕中所见射击:

在此处输入图片说明

Is there some setting or extension I am missing?是否有一些我遗漏的设置或扩展? This is valid HTML code in an Angular 2 app and I don't want a lot of errors for nothing -- but I want to use the linter in case I make actual errors elsewhere.这是 Angular 2 应用程序中的有效 HTML 代码,我不希望出现很多错误——但我想使用 linter,以防我在其他地方出现实际错误。

You can add exceptions to the list of attributes in the HTMLHint extension:您可以在 HTMLHint 扩展中的属性列表中添加例外:

"htmlhint.options": {
    "attr-lowercase": ["*ngIf", "*ngFor"]
}

The attr-lowercase rule can be true, false or an array of attribute names to ignore. attr-lowercase 规则可以是 true、false 或要忽略的属性名称数组。

Just add this fragment into you settings file (.vscode\\settings.json in workspace or edit via File>Preferences>Settings):只需将此片段添加到您的设置文件(工作区中的 .vscode\\settings.json 或通过 File>Preferences>Settings 编辑):

"htmlhint.options": {
    "tagname-lowercase": true,
    "attr-value-double-quotes": true,
    "attr-no-duplication": true,
    "tag-pair": true,
    "spec-char-escape": true,
    "id-unique": true,
    "src-not-empty": true,
    "title-require": true
}

With this, HTMLHint plugin will parse correctly Angular templates and stop throw warnings.有了这个,HTMLHint 插件将正确解析 Angular 模板并停止抛出警告。

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

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