I’m working on a notifications popover where different types of notifications have the same top-level shape, but render differently and carry different information lower down. I’ve been trying to use ngSwitch
to use render custom components for each notification
differently based on notification.type
, but am having issues with its interactions with the ion-item
s in the list. I’ve tried a few different combinations:
Attempt 1: Wrap each ion-item
in a custom component
<ion-list>
<ion-item-sliding *ngFor="let notification of unread" [ngSwitch]="notification.type">
<share-notification *ngSwitchCase="'share'" [notification]="notification"></share-notification>
...other notification types...
<ion-item *ngSwitchDefault>
Something happened, but I'm not sure what it was.
</ion-item>
<ion-item-options side="left" (ionSwipe)="archive(notification)">
...
</ion-item-options>
</ion-item-sliding>
<ion-item *ngIf="unread.length === 0">
No unread notifications.
</ion-item>
</ion-list>
share-notification.html
<button ion-item (tap)="viewDetail()">
<ion-icon item-left name="share"></ion-icon>
<h1>foo</h1>
</button>
Issue: The first time I load the page, it works, but there’s an extra divider line inside the item (the picture below shows the line from the ion-item
, but there is another line across the whole popover just below it, from the ion-list
, I believe). Then, if I try to change something (e.g., add a class) and reload, that ion-item-sliding
has no ion-item
children, just the ion-options
.
Attempt 2: Wrap the contents of each ion-item
in custom components
notification-menu.html
<ion-list>
<ion-item-sliding *ngFor="let notification of unread">
<button ion-item [ngSwitch]="notification.type" (tap)="viewDetail(notification.object)">
<share-notification *ngSwitchCase="'share'" [notification]="notification"></share-notification>
...other notification types...
<div *ngSwitchDefault>
Something happened, but I'm not sure what it was.
</div>
</button>
<ion-item-options side="left" (ionSwipe)="archive(notification)">
...
</ion-item-options>
</ion-item-sliding>
<ion-item *ngIf="unread.length === 0">
No unread notifications.
</ion-item>
</ion-list>
share-notification.html
<ion-icon item-left name="share"></ion-icon>
<h1>foo</h1>
Issue: item-left
and item-right
directives inside share-notification
don’t get applied
I’ve tried a few other possible arrangements of the ngSwitch
, the ion-item
directive, and the custom components, but they all either error or don’t render anything.
Is this a limitation in the framework, or am I doing something wrong? Are there workarounds or better ways of setting up the whole component? Any help would be much appreciated.