【发布时间】:2020-09-24 18:34:04
【问题描述】:
我的服务检索 ExceptionReportSessionData 接口的列表。一个会话可以有许多或没有与之关联的 ReportFiles。我不知道该怎么做是,如果用户从第一个下拉框中选择一个会话,我只希望他们在与该会话关联的第二个下拉框中看到 ReportFiles。
这是我目前拥有的:
component.ts:
export class OrderExceptionReportComponent implements OnInit {
public sessionData: ExceptionReportSessionData[] = [];
currentSession: ExceptionReportSessionData = null;
selectedReport: string;
index: number;
constructor(private orderExceptionReportService: OrderExceptionReportService) {
}
private async getExceptionReportSessionData(): Promise<void> {
this.orderExceptionReportService.GetExceptionReportSessionData()
.then(
data => {
this.sessionData = data;
console.log(this.sessionData)
});
}
sessionDataChange(value: any) {
this.index = value.target.selectedIndex;
this.currentSession = this.sessionData[value.target.selectedIndex];
// this.currentSession = value;
}
ngOnInit() {
this.getExceptionReportSessionData();
}
html:
<div class="dropdown">
<div class="input-group">
<h4>Session: </h4>
<select [(ngModel)]='currentSession'
class="custom-select form-control-sm"
(change)='sessionDataChange($event)'
id="inputGroupSelect01">
<option [value]="null">Select session...</option>
<option *ngFor="let session of sessionData" [value]='session'>
{{session.sessionName}}
</option>
</select>
</div>
<div *ngIf='currentSession' class="input-group">
<h4>Report Date: </h4>
<select [(ngModel)]='selectedReport' class="custom-select form-control-sm" id="inputGroupSelect01">
<option [value]="null">Select report...</option>
<option *ngFor="let report of currentSession.ReportFiles"
[value]="report">
{{report}}
</option>
</select>
</div>
Interface.ts:
export interface ExceptionReportSessionData {
SessionName: string,
ReportFiles: Array<string>
}
【问题讨论】:
标签: html angular typescript filter