如何迭代数组并在angular 2中的下拉选项中追加值?
我使用下面的代码在数组上迭代,并在下拉选项中附加值 searchcomponent.html:-如何迭代数组并在angular 2中的下拉选项中追加值?,angular,typescript,angular2-template,Angular,Typescript,Angular2 Template,我使用下面的代码在数组上迭代,并在下拉选项中附加值 searchcomponent.html:- <div fxFlex.xs="100" class="ddlplatform" *ngFor="let dropdown of dropdownitems"> <select class="ddloption"> <option>{{dropdown}}</option> <option *ngFor="let
<div fxFlex.xs="100" class="ddlplatform" *ngFor="let dropdown of dropdownitems">
<select class="ddloption">
<option>{{dropdown}}</option>
<option *ngFor="let item of dropdown">{{item}}</option>
</select>
</div>
OnOptionChange(evt) {
this.dropdownitems = ['Platform', 'Category'];
this.Platform = ['Online', 'Offline'];
this.Category = ['2W', '3W', '4W'];
}
有两个下拉列表可用,即平台和类别。在平台下拉列表中,我想绑定联机和脱机选项。如何在下拉列表中动态绑定选项 您实际上可以在模板中使用
此
,以帮助通过组件的键引用组件的属性。通过利用此功能,您可以动态获取作为根属性的数组,并在*ngFor
中使用它
<div fxFlex.xs="100" class="ddlplatform" *ngFor="let dropdown of dropdownitems">
<select class="ddloption">
<option>{{dropdown}}</option>
<option *ngFor="let item of this[dropdown]" [value]="item">{{item}}</option>
</select>
</div>
HTML:
{{dropdown.type}
{{item}}
OnOptionChange(evt) {
this.dropdownItems = [
{ type: 'Platform', options: ['Online', 'Offline'] },
{ type: 'Category', options: ['2W', '3W', '4W'] }
];
}
<div fxFlex.xs="100" class="ddlplatform" *ngFor="let dropdown of dropdownitems">
<select class="ddloption">
<option>{{dropdown.type}}</option>
<option *ngFor="let item of dropdown.options" [value]="item">{{item}}</option>
</select>
</div>