TLDR:下拉列表是对象列表。不确定如何捕获所选对象的多个属性。
我目前正在做什么:
我有一个简单的下拉列表,显示通过API调用返回的obj的详细信息:
<mat-form-field class="testSection">
<mat-label>Available Test Results:</mat-label>
<mat-select [(ngModel)]="testName" name="testName" ngDefaultControl>
<mat-option *ngFor="let test of tests" [value]="test.testName">
{{ test.testName + test.testType + test.results + test.cohortId}}
</mat-option>
</mat-select>
</mat-form-field>
在我的component.ts上,我有一个testName定义为字符串:
testName: string
因此,我确实能够根据用户在下拉列表中选择的内容(基于用户单击的特定test.testName
)来检索正确的test
我需要什么:
[我想进一步扩展它。可以说我想要[[both test.name
和test.results
并将它们分配给变量testName
和testResults
以用于进一步的API调用。我该怎么做?
[value]="test.testName"
更改为[value]="test.testName, test.testResults"
和[(ngModel)]="testMap"
,其中testMap在组件中定义为:testMap: Map<string, string>
。不幸的是,它什么也没做,我最终只捕获了test.testName。
[(ngModel)]
变量绑定为整个测试对象。像这样: