How to add a badge to a icon inside a ion-button?

I need to add a badge to a ion icon inside a ion-button this way:

How could I do this with Ionic 2?

4 Likes

I was able to achieve this with some CSS:

Template:

<div>
    <button id="notification-button" ion-button clear>
        <ion-icon name="notifications">
          <ion-badge id="notifications-badge" color="danger">5</ion-badge>
        </ion-icon>              
    </button>
</div>

CSS:

  #notification-button {            
            position: relative;
            width: 42px;
            top:1px;
            right: 1px;
            overflow: visible!important;
        }


   #notifications-badge {
            background-color: red;
            position: absolute;
            top: -3px;
            right: -3px;
            border-radius: 100%;
        }
15 Likes

I found it a bit easier this way (inside a <ion-navbar /> wrapped in <ion-buttons end />):

<button ion-button icon-only (click)="showNotifications()">
	<ion-badge *ngIf="n" color="accent">{{ n }}</ion-badge>
	<ion-icon name="notifications"></ion-icon>
</button>
button {
	ion-badge {
		position: absolute;
		top: -0.2rem;
		right: -0.2rem;
		opacity: 0.9;

		& ~ ion-icon {
			margin-right: 1.2rem;
		}
	}
}
4 Likes

bonjour svp comment vs avez fait pour la fonction je trouve pas bcp de doc sur les systèmes de notifications???

nice it’s work
Thanks bro

<ion-avatar slot="end" >
      <ion-badge style="position: absolute">5</ion-badge>
      <img [src]="member?.photoURL" />
    </ion-avatar>

Does it for me. Thank you for the code.