目前,我可以通过使用* ngFor和+1进行正确选择的人数来显示家庭的规模;但这只给我一个选择的机会,我需要i + 10作为人数
我尝试在选项上使用* ngFor失败
<label for="household_size">Household Size *</label>
<select class="custom-select" id="household_size" formControlName="household_size">
<option min="i + 1" *ngFor="let person of getPeoples(); let i = index" [value]="i + 1">{{i + 1}}</option>
<option min="i + 2" *ngFor="let person of getPeoples(); let i = index" [value]="i + 2">{{i + 2}}</option>
<option min="i + 3" *ngFor="let person of getPeoples(); let i = index" [value]="i + 3">{{i + 3}}</option>
<option min="i + 4" *ngFor="let person of getPeoples(); let i = index" [value]="i + 4">{{i + 4}}</option>
<option min="i + 5" *ngFor="let person of getPeoples(); let i = index" [value]="i + 5">{{i + 5}}</option>
<option min="i + 6" *ngFor="let person of getPeoples(); let i = index" [value]="i + 6">{{i + 6}}</option>
<option min="i + 7" *ngFor="let person of getPeoples(); let i = index" [value]="i + 7">{{i + 7}}</option>
<option max="i + 8" *ngFor="let person of getPeoples(); let i = index" [value]="i + 8">{{i + 8}}</option>
<option max="i + 9" *ngFor="let person of getPeoples(); let i = index" [value]="i + 9">{{i + 9}}</option>
<option max="i + 10" *ngFor="let person of getPeoples(); let i = index" [value]="i + 10">{{i + 10}}</option>
<option max="i + 11" *ngFor="let person of getPeoples(); let i = index" [value]="i + 11">{{i + 11}}</option>
</select>
应该有一个包含11个选项1、2、3等的下拉列表。
答案 0 :(得分:0)
<select class="custom-select" id="household_size" formControlName="household_size">
<option min="i + 1" *ngFor="let person of getPeoples(); let i = index" [value]="i + 1">{{i + 1}}</option>
</select>
答案 1 :(得分:0)
在TS中解决了这个问题
householdSizeOptions = [];
getAmountOfPeople(){
this.householdSizeOptions = [];
for (let i = this.getPeoples().length; i < this.getPeoples().length + 10; i++){
this.householdSizeOptions.push(i);
}
}
这在HTML中
<select class="custom-select" id="household_size" formControlName="household_size">
<option *ngFor="let count of householdSizeOptions" [value]="count">{{count}}</option>
</select>