我有一个下拉菜单,当我选择此下拉列表的一个元素时,我想提取其所有数据。
我的.ts是:
completeInputAgencyAndVersion(event: MatSelectChange) {
if (event.value > 0) {
this.service.getCodeList(event.value).subscribe(val => { this.currCodeList = val; });
if (this.currCodeList) {
this.contextScheme.schemeId = this.currCodeList.listId.toString();
this.contextScheme.schemeAgencyId = this.currCodeList.agencyId.toString();
this.contextScheme.schemeVersionId = this.currCodeList.versionId.toString();
// this.contextScheme.ctxSchemeValues = this.convertCodeListValuesIntoContextSchemeValues(this.currCodeList.codeListValues);
this._updateDataSource(this.convertCodeListValuesIntoContextSchemeValues(this.currCodeList.codeListValues));
// this.dataSource.data = this.contextScheme.ctxSchemeValues;
}
} else {
this.contextScheme.schemeId = '';
this.contextScheme.schemeAgencyId = '';
this.contextScheme.schemeVersionId = '';
this._updateDataSource([]);
}
}
我的.html是:
<mat-form-field>
<mat-select placeholder="Code List" [(ngModel)]="contextScheme.codeListId" (selectionChange)="completeInputAgencyAndVersion($event)">
<mat-option [value]="0"> None </mat-option>
<mat-option *ngFor="let codeList of codeListsFromCodeList" [(value)]="codeList.codeListId">
{{codeList?.codeListName}}
</mat-option>
</mat-select>
</mat-form-field>
一切都工作正常,除了因为我使用mat-select的selectionChange方法,当我选择第一个值时,它不被理解为变化,因此没有任何反应。然后,当我选择另一个元素时,它只是获取正确的信息,但从最后的选择,基本上是selectionChange的bc。
我已经发布了堆栈:Offset selectionChange Angular您可以查看更多信息。
谢谢 。
我不确定我是否完全明白你的意思,但你会通过[(value)]
得到数据。
如果你正在寻找codeList
,你可以改变:
[(value)]="codeList.codeListId"
到[(value)]="codeList"
。
像这样它应该选择你的codeList
它不是selectionChange
它是subscribe
异步。我不得不添加另一个异步方法来修复它,现在它可以正常工作。谢谢 !