2016-10-19 4 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> 
関連する問題