首页 > 解决方案 > 带有 labelForId 和 id 的 ng-select

问题描述

似乎 labelForId 用于 ng-Select ( https://github.com/ng-select ),它也有一个 ID它不起作用,即点击标签不会跳转到元素中。

如果我没有在 ng-select 的定义中添加 ID,它会起作用,但我的 IDE(intelliJ)会抛出"invalid id reference"查看https://github.com/ng-select/ng-select/issues/1993上的附加图片

div class="row margin-top-25">
    <div class="col-4">
        <label for="one">One (WORKS  but makes the IDE red)</label>
    </div>
    <div class="col-8">
        <ng-select
                labelForId="one">
            <ng-option>Dog</ng-option>
            <ng-option>Cat</ng-option>
        </ng-select>
    </div>
</div>

<div class="row margin-top-25">
    <div class="col-4">
        <label for="two">Two (DOES NOT WORK ☹️)</label>
    </div>
    <div class="col-8">
        <ng-select
                id="two"
                labelForId="two">
            <ng-option>Dog</ng-option>
            <ng-option>Cat</ng-option>
        </ng-select>
    </div>
</div>

更新

对于每个有相同问题的人: https ://github.com/ng-select/ng-select/issues/1993#issuecomment-961218459

标签: angular-ngselect

解决方案


推荐阅读