angular2 和 ngIf - 测试是否大于或小于
angular2 and ngIf - test if greater or less than
我该如何进行这项工作?如果值为 9 或更小,则显示 "Month",否则显示 "Months"。这是我的代码:
<select id="analysis_horizon" class="custom-select form-control" [(ngModel)]="basic_setup.analysis_horizon" formControlName="analysis_horizon" describedby="basic-addon_analysis_horizon">
<option disabled>Select Analysis Horizon</option>
<option *ngIf="'i<=9'" *ngFor="let i of analysis_horizon_array">{{i}} Month</option>
<option *ngIf="'i>9'" *ngFor="let i of analysis_horizon_array">{{i}} Months</option>
</select>
这是我得到的错误:
Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with * ("isabled>Select Analysis Horizon
]*ngFor="let i of analysis_horizon_array">{{i}} Month
{{i}} Month
9'" [ERROR ->]*ngFor="let i of analysis_horizon_array">{{i}} Months
; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse errors:
Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with * ("isabled>Select Analysis Horizon
]*ngFor="let i of analysis_horizon_array">{{i}} Month
{{i}} Month
9'" [ERROR ->]*ngFor="let i of analysis_horizon_array">{{i}} Months
您不能在一个元素上使用多个模板绑定,在本例中为 *ngIf
和 *ngFor
。你可以用插值和三元运算符实现你想要的,你不需要使用 *ngIf
指令:
<select id="analysis_horizon" class="custom-select form-control" [(ngModel)]="basic_setup.analysis_horizon" formControlName="analysis_horizon" describedby="basic-addon_analysis_horizon">
<option disabled>Select Analysis Horizon</option>
<option *ngFor="let i of analysis_horizon_array">
{{i}} {{ i <= 9 ? "Month" : "Months" }}
</option>
</select>
我该如何进行这项工作?如果值为 9 或更小,则显示 "Month",否则显示 "Months"。这是我的代码:
<select id="analysis_horizon" class="custom-select form-control" [(ngModel)]="basic_setup.analysis_horizon" formControlName="analysis_horizon" describedby="basic-addon_analysis_horizon">
<option disabled>Select Analysis Horizon</option>
<option *ngIf="'i<=9'" *ngFor="let i of analysis_horizon_array">{{i}} Month</option>
<option *ngIf="'i>9'" *ngFor="let i of analysis_horizon_array">{{i}} Months</option>
</select>
这是我得到的错误:
Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with * ("isabled>Select Analysis Horizon ]*ngFor="let i of analysis_horizon_array">{{i}} Month {{i}} Month 9'" [ERROR ->]*ngFor="let i of analysis_horizon_array">{{i}} Months ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse errors: Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with * ("isabled>Select Analysis Horizon ]*ngFor="let i of analysis_horizon_array">{{i}} Month {{i}} Month 9'" [ERROR ->]*ngFor="let i of analysis_horizon_array">{{i}} Months
您不能在一个元素上使用多个模板绑定,在本例中为 *ngIf
和 *ngFor
。你可以用插值和三元运算符实现你想要的,你不需要使用 *ngIf
指令:
<select id="analysis_horizon" class="custom-select form-control" [(ngModel)]="basic_setup.analysis_horizon" formControlName="analysis_horizon" describedby="basic-addon_analysis_horizon">
<option disabled>Select Analysis Horizon</option>
<option *ngFor="let i of analysis_horizon_array">
{{i}} {{ i <= 9 ? "Month" : "Months" }}
</option>
</select>