2017-08-02 3 views
1

私は修正できないような論理エラーがありますが、リテラルロジックエラーを除いて、なぜAngularはこれをやりませんか?ngSwitchの条件付きボタンとngFor with async piped array

私はジェンダーをdrop.Nameでドロップダウンしていますが、レンダリング時に[オブジェクトオブジェクト]がドロップダウンに表示されるだけです。

着信コード:

<drop-down [Content]="GenderTxt" [AriaLabel]="'Gender Select'" [Type]="'Gender'" [Options]="(MenuOptions | async)?.Genders" 
      (Click)="SetGender($event)"> 
      </drop-down> 

エラーメッセージ:

Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with * ("aria-labelledby="{{AriaLabel}}"> 
    <div [ngSwitch]="Type"> 
     <button *ngSwitchCase="Gender" [ERROR ->]*ngFor="let drop of Options" class="dropdown-item FakeClickable" (click)="Clicked(drop)">{{drop.Name}"): ng:///AppModule/[email protected]:37 
Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with * ("-item FakeClickable" (click)="Clicked(drop)">{{drop.Name}}</button> 
     <button *ngSwitchDefault [ERROR ->]*ngFor="let drop of Options" class="dropdown-item FakeClickable" (click)="Clicked(drop)">{{drop}}</bu"): ng:///AppModule/[email protected]:31 

コード:基本的に私は外側のレベルにスイッチケースを上に移動する必要が私の問題は

<div class="dropdown-menu" attr.aria-labelledby="{{AriaLabel}}" [ngSwitch]="Type"> 
    <button *ngSwitchCase="Gender" *ngFor="let drop of Options" class="dropdown-item FakeClickable" (click)="Clicked(drop)">{{drop.Name}}</button> 
    <button *ngSwitchDefault *ngFor="let drop of Options" class="dropdown-item FakeClickable" (click)="Clicked(drop)">{{drop}}</button> 
    </div> 

ですdivを作成し、各ボタンに対して新しいdivを作成しますか?

+0

の可能性のある重複した[angular2 RC4に一つの要素に複数のテンプレートバインディングを適用する方法](https://stackoverflow.com/questions/38585720/how-to-apply-multiple-template- bindings-on-one-angular-2-rc4) –

答えて

1

同じ要素に2つの構造ディレクティブを使用することはできません。代わりにこれを試してみてください:

<div class="dropdown-menu" attr.aria-labelledby="{{AriaLabel}}" [ngSwitch]="Type"> 
    <ng-container *ngSwitchCase="Gender"> 
     <button *ngFor="let drop of Options" class="dropdown-item FakeClickable" (click)="Clicked(drop)">{{drop.Name}}</button> 
    </ng-container> 
    <ng-container *ngSwitchDefault> 
     <button *ngFor="let drop of Options" class="dropdown-item FakeClickable" (click)="Clicked(drop)">{{drop}}</button> 
    </ng-container> 
</div> 
+0

私はそれが問題だと考えましたが、使いやすさのために再構成する方法を知らなかった。 –

+0

私は更新中のこの質問の次の部分に答えることができます。 –

+0

@BaileyMiller質問の第2部分を記述するプランナーを作成できますか? – yurzui

関連する問題