angular
The <glorpie-face> element in Angular templates.
❯
npm i glorpiesuse it
Import the element once, and add CUSTOM_ELEMENTS_SCHEMA to the components that use it:
user-badge.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA, input } from '@angular/core';import 'glorpies/element'; @Component({ selector: 'user-badge', schemas: [CUSTOM_ELEMENTS_SCHEMA], template: `<glorpie-face [name]="email()" size="40" [label]="name()"></glorpie-face>`,})export class UserBadge { email = input.required<string>(); name = input('Avatar');}Every option is both an attribute and a property, so [name] and [attr.name] bindings both work for strings. Use [name] for a numeric seed: attribute bindings turn numbers into string names.
errors
If a face fails to paint, the element dispatches glorpie-error with the error as detail. Call preventDefault() to suppress the console.error.
html
<glorpie-face [name]="user.id" (glorpie-error)="report($event.detail); $event.preventDefault()"></glorpie-face>server rendering
With Angular SSR the element is rendered as an empty tag and upgrades in the browser. Size it in CSS to reserve its space:
css
glorpie-face { width: 40px; height: 40px; }Why no Angular component? Angular libraries must be compiled with ng-packagr and published as a separate package. Angular handles custom elements natively, so the element is the supported path for now.