[英]Offset on a SelectionChange mat-select Angular
我有一个下拉菜单,当我选择这个下拉菜单的一个元素时,我想提取它的所有数据。
我的 .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
。 我不得不添加另一个异步方法来修复它,现在它可以工作了。 谢谢 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.