[英]Offset on a SelectionChange mat-select Angular
I have a dropdown menu and when I select a element of this dropdown I want to extract all its data.我有一个下拉菜单,当我选择这个下拉菜单的一个元素时,我想提取它的所有数据。
My .ts is :
我的 .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([]);
}
}
And my .html is :
我的 .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>
Everything is working fine except that since I m using the selectionChange method of mat-select , when I chose the first value, it s not understood as a change and therefore nothing happens.一切正常,除了因为我使用的是 mat-select 的 selectionChange 方法,当我选择第一个值时,它不被理解为更改,因此没有任何反应。 Then after that when I select another element, it just get the correct information but from the last selection, basically bc of the selectionChange.
然后当我选择另一个元素时,它只是从最后一个选择中获得正确的信息,基本上是 selectionChange 的 bc。
I have already posted on stack : Offset selectionChange Angular you can check for further information.我已经在堆栈上发布了: Offset selectionChange Angular,您可以查看更多信息。
Thank you .谢谢你 。
I'm not sure i've fully understood what you mean, but you'll get the data throught [(value)]
.我不确定我是否完全理解你的意思,但你会通过
[(value)]
获得数据。
If you're looking for codeList
, you can you just change:如果您正在寻找
codeList
,您可以更改:
[(value)]="codeList.codeListId"
to [(value)]="codeList"
. [(value)]="codeList.codeListId"
到[(value)]="codeList"
。
Like this it should pick your codeList像这样它应该选择你的 codeList
It was not the selectionChange
it was the subscribe
that were async.这不是
selectionChange
而是异步的subscribe
。 I had to add another async method to fix it and now it works.我不得不添加另一个异步方法来修复它,现在它可以工作了。 Thanks !
谢谢 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.