https://stackblitz.com/edit/angular-f2fovj
MatBadge should preserve its position after content is updated
MatBadge changes position after content is updated.

Ok, the solution for this problem is not to use matBadge with _inline_ elements.
Is it supposed to be fixed or is it a limitation ?
I have strange behaviors too using badges with h1, h2 tags. The badge is moved to the right end of the page.
Regards
I found a hack for this issue
Use <mat-icon></mat-icon>
eg:
<mat-icon class="badge-icon" [matBadge]="data.responses?.length" matBadgePosition="above after"
matBadgeOverlap="false" matBadgeSize="small" [matBadgeHidden]="data.responses.length < 1"></mat-icon>
You can also just add "display: inline-block;" to the inline element instead of using mat-icon around it.
Also affected with an Angular 10 (CLI 10.2.0, Material 10.2.7) application using a mat-checkbox inside a table header cell.
Worked around through the mat-icon as such :
<th mat-header-cell *matHeaderCellDef>
<mat-checkbox
...
- [matBadgeColor]="items.length === 0 ? 'warn' : 'primary'"
- [matBadge]="items.length"
></mat-checkbox>
+ <mat-icon
+ class="mat-checkbox-icon-badge"
+ [matBadgeColor]="items.length === 0 ? 'warn' : 'primary'"
+ [matBadge]="items.length"
+ matBadgePosition="above after"
+ matBadgeOverlap="true"
+ ></mat-icon>
</th>
+.mat-checkbox-icon-badge {
+ height: 0px;
+ width: 0px;
+
+ .mat-badge-content {
+ right: -14px;
+ top: -25px;
+ }
+}
I use Font Awesome instead of Angular Icons and have the same issue. (I won't use Material Icons because they suck 馃構)
Any news? :)
Most helpful comment
You can also just add "display: inline-block;" to the inline element instead of using mat-icon around it.