【问题标题】:Angular interpolation in HTML attribute nameHTML 属性名称中的角度插值
【发布时间】:2020-04-03 17:27:04
【问题描述】:

我正在使用 IntelliJ,它知道 {{foo}} 是 formControlName 属性中的插值。但在 name 属性中它没有。 IntelliJ 在名称属性中认为 {{foo}} 是一个数组,我缺少一个 : 就像在 {foo : bar} 中一样。

代码编译得很好,这是 IntelliJ-Bug 还是我很幸运编译器接受了它?

<input type="radio" name="{{foo}}" formControlName="{{foo}}">

【问题讨论】:

    标签: html angular intellij-idea interpolation


    【解决方案1】:

    Angular 绝对允许在属性中进行插值,但通常首选的方法(主要是为了可读性)是属性绑定。 name="{{foo}}" [name]="foo" more info here

    所以你提供的代码

    <input type="radio" name="{{foo}}" formControlName="{{foo}}">
    

    变成

    <input type="radio" [name]="foo" [formControlName]="foo">
    

    这应该会让 IntelliJ 停止抱怨。

    【讨论】:

    • 是的!谢谢队友:)
    猜你喜欢
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 2013-01-29
    • 2015-06-09
    • 1970-01-01
    • 2011-05-28
    相关资源
    最近更新 更多