从下拉菜单中绑定对象的属性不同的对象属性

问题描述 投票:0回答:1

我试图从下拉列表中选择的选项绑定到数据表内的生活的特定对象的属性。请在下面的代码。

<data-table-column [property]="'CostTypeId'"
                   [header]="'Type'"
                   [sortable]="false"
                   [resizable]="true">
    <ng-template #dataTableCell let-item="item">
        <select class="form-control form-control-sm mt-1"
                [(ngModel)]="item.CostTypeId"
                [class.is-invalid]="validateCostType(item)">
            <option *ngFor="let type of recoveryCostTypes" [(ngValue)]="type.Id">{{type.Description}}</option>
        </select>
    </ng-template>
</data-table-column>

但我不能够通过得到的值。我一直说的item.CostTypeId属性未定义。难道我也许不正确地结合?

html angular typescript angular-datatables
1个回答
0
投票

有不同的ngModel属性可以说“modelValue”当下拉值更改dropdownChange()函数被调用,指定下拉值到DataTable的selectedRow。

<select class="form-control form-control-sm mt-1"
                [(ngModel)]="modelValue" (change)="dropdownChange(modelValue)"
                [class.is-invalid]="validateCostType(item)">
            <option *ngFor="let type of recoveryCostTypes" [(ngValue)]="type.Id"> 
            {{type.Description}}</option>
</select>

在.TS文件

modelValue: string;
selectedRow = {};

dropdownChange(value){
  selectedRow.CostTypeId = value;
}
© www.soinside.com 2019 - 2024. All rights reserved.