2016-08-19 66 views
0

JoinedArray是一个包含一些值的数组。 我必须检查event.listDetails.accessId是否存在于数组中。如果ACCESSID是不存在的数组中,则此事件卡不能打印在Angulsrjs2和Ionic中使用ngFor和ngIf接收错误2

<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)方法来查看数组是否包含该值。