Angular Avatar Component | ng-hub-ui-avatar

Angular avatar component with initials, fallback images, presence badges and CSS variables for reusable user identity interfaces.

API reference

Here's the full contract for avatar: everything you can bind, listen to, project and theme, gathered in one place. Wire up what you need and style what you want — it's standalone and signal-friendly.

Inputs

Dial avatar in with 22 inputs. Bind them like any Angular @Input.

NameTypeDefaultDescription
sizestring | number50Avatar size: a bare number is pixels; any CSS length (1.75rem, 50%, calc(2rem + 12px)) is painted as written
namestring | null—User name for generating initials when image sources fail
srcstring | SafeUrl | null—Primary custom image source URL for the avatar
altstring | null—Alternative text for the avatar image for accessibility
roundbooleantrueWhether the avatar should be circular (true) or follow cornerRadius
interactivebooleanfalseMarks the avatar as an interactive control: exposes role=“button”, makes it focusable and fires clickOnAvatar with Enter/Space. Enable it whenever you bind (clickOnAvatar).
bgColorstring—Background color for text avatars. Auto-generated if not provided
autoColorbooleantrueWhen `true` (default) an initials avatar derives its background from a hash of the name. Set to `false` to theme it through the `--hub-avatar-bg-color` variable instead; an explicit `bgColor` always wins.
fgColorstring | undefined—Colour of the initials and of projected content. Leave it unset and the avatar picks black or white per background, whichever clears WCAG AA; an explicit value always wins, contrast or not.
borderColorstring—Border color around the avatar
cornerRadiusstring | number0Corner radius when round is false
textSizeRationumber3Ratio to calculate text size from avatar size (size / textSizeRatio)
initialsSizestring | number0Restricts the number of initials displayed (0 = no restriction)
facebookIdstring | null—Facebook user ID for profile picture (best-effort, API restrictions may apply)
githubIdstring | null—GitHub username for fetching profile picture
gravatarIdstring | null—Gravatar email or MD5 hash for fetching profile picture
valuestring | null—Display a custom value as avatar (e.g., "75%", "+5")
styleRecord<string, string | number | null | undefined> | string—Inline styles merged into the rendered content — the image, the initials or the projected-content slot. Accepts a style object or a CSS string; it never reaches the host element
referrerpolicystring | null—Referrer policy for the avatar image (e.g., "no-referrer")
placeholderstring—Picture of last resort: painted only while nothing else is — no source resolved, none was declared, or one is still loading — and there are no initials either. It never joins the fallback chain, so it cannot outrank the initials the way `src` would.
badgestring | number | boolean | nullnullCorner overlay: `badge` / `[badge]="true"` → a dot; `badge="4k"` → a labelled pill; null / absent → nothing.
badgeColorHubAvatarBadgeColor | string | nullnullSemantic colour of the badge (primary · secondary · success · danger · warning · info · light · dark) → `--hub-sys-color-*`.

Outputs

React to what avatar does — 1 events to hook your logic onto.

NameTypeDescription
clickOnAvatarOutputEmitterRef<Source | null>Emitted on click, and on Enter/Space when `interactive` is set. Carries the source painting the avatar — its `sourceType`, its `sourceId` and `getAvatar(size)` — or null when none has resolved. `Source` is exported from the package, so the handler can name the type instead of falling back to any

Methods

Drive avatar from code — 1 methods on its programmatic surface.

NameSignatureReturnsDescription
Source.getAvatargetAvatar(size: number): stringstringResolves what the source paints at a given size: the picture URL for a remote source, the initials or the plain text for a local one. `Source` is the payload of `clickOnAvatar` and is exported from the package.

Templates

No templates documented yet.