我已经在 Angular 7 应用程序中实现了一个下拉控件,并且在值更改时,我正在过滤集合并将其分配给绑定到视图的对象。我正在过滤的集合对象称为FundTerms
,我分配的绑定到视图的对象称为 Fund。我已经在编写过滤逻辑的组件中实现了值更改事件。
我可以看到valueChanged
事件被触发并执行了逻辑,但 UI 没有反映VehicleType
字段中更改的值。
我在视图中有两个控件。一个是下拉控件,即名称,另一个是根据在名称控件的下拉列表中选择的内容VehicleType
显示的字段。VehicleType
零件
import { Component, OnInit, AfterViewInit,AfterViewChecked, AfterContentInit, Input, ViewChild, Output, EventEmitter } from '@angular/core';
import { TermsService } from '../../services/terms.service';
import { NotifyService } from '../../utilities/notify.service';
@Component({
selector: 'app-fund-terms',
templateUrl: './fundTerms.component.html'
})
export class FundTermsComponent implements OnInit {
@Input() Funds: any;
public Fund: any;
_fundTerms: any;
get FundTerms(): any {
return this._fundTerms;
}
@Input('FundTerms')
set FundTerms(value: any) {
this._fundTerms = value;
if (this._fundTerms) {
this.Fund = this._fundTerms[0];
}
}
public EditMode = false;
ngOnInit() {
}
public fundChanged(value: any): void {
this.Fund = this.FundTerms.filter(x => x.Id === value.Id);
}
}
看法
<div *ngIf="Fund">
<div class="card-body">
<div class="form-group row" style="width: 100%;">
<div class="col-md-4">
<label for="inputName" class="col-form-label modal-label">Name</label>
<div *ngIf="!EditMode">{{Fund.Name}}</div>
<kendo-dropdownlist *ngIf="EditMode" style="width:100%" [(ngModel)]="FundClass"
class="form-control form-control-sm" [data]="Funds" [filterable]="false" textField="Name"
[valuePrimitive]="false" valueField="Id" (valueChange)="fundChanged($event)">
</kendo-dropdownlist>
</div>
<div class="col-md-4">
<label for="inputTitle" class="col-md-2 col-form-label ">Vehicle Type</label>
<div>{{Fund.VehicleTypeName}}</div>
</div>
</div>
</div>
</div>
JSON
[
{
"Id": 5508,
"Name": "Sylebra Capital Partners (Offshore) Ltd",
"VehicleTypeId": 5,
"VehicleTypeName": "Offshore Fund",
"InvestmentManager": null,
"NavReportingCycleId": null,
"NavReportingCycleName": "",
"CurrencyId": null,
"CurrencyName": "",
"SideLetterAgreement": false,
"SideLetterText": null,
"PlanAssetFund": null,
"AuditYearEnd": null,
"AuditYearEndString": ""
},
{
"Id": 237146,
"Name": "P Sylebra Ltd.",
"VehicleTypeId": 7,
"VehicleTypeName": "EnTrustPermal SPF - Standard",
"InvestmentManager": null,
"NavReportingCycleId": null,
"NavReportingCycleName": "",
"CurrencyId": null,
"CurrencyName": "",
"SideLetterAgreement": false,
"SideLetterText": null,
"PlanAssetFund": null,
"AuditYearEnd": null,
"AuditYearEndString": ""
},
{
"Id": 237147,
"Name": "Sylebra Capital Partners (Onshore), Ltd",
"VehicleTypeId": 9,
"VehicleTypeName": "",
"InvestmentManager": null,
"NavReportingCycleId": null,
"NavReportingCycleName": "",
"CurrencyId": null,
"CurrencyName": "",
"SideLetterAgreement": false,
"SideLetterText": null,
"PlanAssetFund": null,
"AuditYearEnd": null,
"AuditYearEndString": ""
}
]