ng-select 获取对象作为从中选择的值

Guy*_*y E 2 ngmodel angular

我正在使用 ng-select(来自“@ng-select/ng-select”的 NgSelectModule)?这是我的代码:

 <ng-container *ngFor="let validFilter of validFiltersData; let i = index" >
                <div *ngIf="validFilter.Values && validFilter.Values.length > 0" class=" filter col-md-4 ">
                        <ng-select [items]="validFilter.Values" bindLabel="Text" bindValue="ID" (change)= "onFilterValueChage($event, validFilter)" class="input-md" 
                        [(ngModel)]="validFilter.selectedValue"></ng-select>
                    </div>
            </ng-container>
Run Code Online (Sandbox Code Playgroud)

validFiltersData 是一个 FilterData 数组

export class FilterData 
{
    Name : string;
    FormattedName : string = null;
    Values : Filter[];
    selectedValue : Filter = null;
    ...
}
Run Code Online (Sandbox Code Playgroud)

过滤器

export class Filter 
{
    public ID: number;
    public Text: string;
    ....
}
Run Code Online (Sandbox Code Playgroud)

我试图将选定的值作为包含 ID 和文本的对象(过滤器),但我总是只得到 ID

如何将所有过滤器作为选定值?

Cor*_*elC 9

因为您将绑定设置为 ID: bindValue="ID"。删除它,它应该可以工作。

在此处阅读有关绑定的更多信息:https : //ng-select.github.io/ng-select#/bindings