Angular Ionic 2*ngFor环路if索引3
在我的侧菜单模板中,我使用ngFor循环来显示所有项目。请参阅下文:-Angular Ionic 2*ngFor环路if索引3,angular,ionic2,Angular,Ionic2,在我的侧菜单模板中,我使用ngFor循环来显示所有项目。请参阅下文:- <ion-item menuClose ion-item *ngFor="let page of pages" (click)="openPage(page)"> <ion-icon [name]="page.icon" item-left></ion-icon> {{page.title | translate}} </ion-item> {{page.ti
<ion-item menuClose ion-item *ngFor="let page of pages" (click)="openPage(page)">
<ion-icon [name]="page.icon" item-left></ion-icon>
{{page.title | translate}}
</ion-item>
{{page.title | translate}}
但我想要一个具有不同回调函数的菜单项,如下所示:-
<ion-item menuClose ion-item (click)="openAnotherPage(136379)">
<ion-icon name="home" item-left></ion-icon>
New Menu
</ion-item>
新菜单
但问题是我想要的菜单项将调用第三个位置的openAnotherPage
当前“页面”有8行,我无法调用循环之间的“新菜单”项
是否可以检查索引并更新回调函数和菜单名
<ion-item menuClose ion-item *ngFor="let page of pages" **Like if index 3 **(click)="AnotheropenPage(page)" **and for the rest** (click)="openPage(page)">
请建议 您可以在这里简单地使用三元运算符
(click)="index === 3 ? AnotheropenPage(page): openPage(page)"
或者,您可以将此条件逻辑转换为组件方法本身
你可以试试这个
PS:-我将div
作为父容器,我不熟悉爱奥尼亚,因此请进行适当更改
可以在app.component.ts
文件中配置openPage(page)
方法
您可以通过app.html
<button menuClose ion-item *ngFor="let p of pages; let i = index" (click)="openPage(p,i)"
<button menuClose ion-item *ngFor="let p of pages; let i = index" (click)="openPage(p,i)"
openPage(page,index) {
this.rootPage = index != 3 ? page : AnotherPage;
// AnotherPage can also be a method like this.anotherPage(136379);
}