2016-10-19 3 views
1

어떻게하면됩니까? 값이 9 이하이면 "월"을 표시하고 그렇지 않으면 "월"을 표시합니다.angular2 및 ngIf - 더 크거나 작은 경우 테스트

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

답변

2

당신은이 경우 *ngIf*ngFor에서, 하나 개의 요소에 여러 개의 템플릿 바인딩을 사용할 수 없습니다

<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> 

이것은 내가 오류는 다음과 같습니다 여기에 내 코드입니다. 보간 및 삼항 연산자로 원하는 것을 얻을 수 있지만 *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>