2016-08-19 7 views
0

JoinedArrayはいくつかの値を持つ配列です。 event.listDetails.accessIdが配列内に存在するかどうかをチェックする必要があります。 accessIdが配列に存在しない場合、イベントカードは印刷されませすべきAngulsrjs2とIonic 2でngForとngIfを使用した受信エラー

<ion-list *ngSwitchCase="'joined'"> 
      <event-card *ngIf="event.listDetails.accessId in joinedArray " ></event-card> 
    </ion-list> 

エラーは次のとおりです。

EXCEPTION: Error: Uncaught (in promise): Template parse errors: Property binding ngIfIn not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "directives" section. ("e keys and i have to check if it is present in the array or not ..please suggest-->--> [ERROR ->] "): [email protected]:12

答えて

0

代わりのビューでロジックは、あなただけのプロパティを作成することができることなど、ビュー内の

public showCard: bool; 

// In the constructor or somewhere else 
//... 
this.showCard = joinedArray.indexOf(event.listDetails.accessId) > -1; 
// ... 

そして:

このようなコンポーネントで
<ion-list *ngSwitchCase="'joined'"> 
    <event-card *ngIf="showCard"></event-card> 
</ion-list> 

私たちは物事をシンプルに保つように、ビューは物を表示したり隠したりするだけです。コンポーネントコードはそれを表示するかどうかを決定します。

indexOf()Reference)メソッドを使用して配列にその値が含まれているかどうかを確認していることにも注意してください。

関連する問題