@molecule/app-root-error-boundary-angular
Feature · error-boundary · App (browser) · v1.1.3 · Apache-2.0
Top-level Angular error boundary that logs render errors via the bonded app logger and shows a minimal recovery surface
npm install @molecule/app-root-error-boundary-angularHow it works
@molecule/app-root-error-boundary-angular is a ready-made error-boundary feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import { Component } from '@angular/core'
import { RootErrorBoundary } from '@molecule/app-root-error-boundary-angular'
@Component({
selector: 'app-root',
standalone: true,
imports: [RootErrorBoundary],
template: `
<mol-root-error-boundary>
<router-outlet />
</mol-root-error-boundary>
`,
})
export class AppRoot {}Works with: @molecule/app-angular, @molecule/app-i18n, @molecule/app-logger, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular top-level error boundary — the counterpart of
@molecule/app-root-error-boundary-react: the same props and the same DOM
for the same input.
Exports <RootErrorBoundary> (projected children, or a content
TemplateRef input for a tree the boundary instantiates inside its own
view). Mount it directly under your routing root so it covers the whole
route tree.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { Component } from '@angular/core'
import { RootErrorBoundary } from '@molecule/app-root-error-boundary-angular'
@Component({
selector: 'app-root',
standalone: true,
imports: [RootErrorBoundary],
template: `
<mol-root-error-boundary>
<router-outlet />
</mol-root-error-boundary>
`,
})
export class AppRoot {}
Type
feature
Installation
npm install @molecule/app-root-error-boundary-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-i18n @molecule/app-logger @molecule/app-ui @molecule/app-ui-angular
API
Classes
RootErrorBoundary
RootErrorBoundary component.
Top-level error boundary that catches descendant render errors, reports
them via the bonded @molecule/app-logger, and falls back to a minimal
localized recovery surface read through useTranslation() from
@molecule/app-angular. It renders its children untouched while no error
has been caught — there is no wrapper element, matching React's fragment
root, so the content stands in front of the host's place and the host itself
leaves the page (placeContentBefore + setElementPresent).
This is the Angular counterpart of @molecule/app-root-error-boundary-react.
@Component({
selector: 'mol-root-error-boundary',
standalone: true,
imports: [NgTemplateOutlet, RootErrorFallback],
hostDirectives: [MolPlacement],
inputs: ['content'],
template: `@boundary {
@if (contentTemplate(); as tpl) {
<ng-container [ngTemplateOutlet]="tpl"></ng-container>
} @else {
<ng-content></ng-content>
}
} @error (caught = $error) {
<div mol-root-error-fallback [error]="caught"></div>
}`,
})
export class RootErrorBoundary implements OnChanges {
/** The protected content template, when the caller passed one. */
content?: TemplateRef<unknown>
/** The template as a signal, so the `@if` re-renders when the input lands. */
readonly contentTemplate = signal<TemplateRef<unknown> | undefined>(undefined)
/** The component's host element (React renders no element of its own). */
private readonly host: ElementRef<HTMLElement> = inject(ElementRef)
constructor() {
// React's root is a fragment (children or the fallback): the content renders in front
// of the host's place and the host leaves the page.
usePlacement(() => {
placeContentBefore(this.host.nativeElement, this.host.nativeElement)
setElementPresent(this.host.nativeElement, false)
})
}
/**
* Mirrors the input into the signal.
* @param changes - The changed inputs.
*/
ngOnChanges(changes: SimpleChanges): void {
if (changes['content']) this.contentTemplate.set(this.content)
}
}
Injection Notes
Requirements
Peer dependencies:
@angular/common^22.0.0@angular/core^22.0.0@angular/platform-browser^22.0.0@molecule/app-angular^3.13.0 || ^4.0.0@molecule/app-i18n^1.0.1@molecule/app-logger^1.0.1@molecule/app-ui^1.0.1@molecule/app-ui-angular^1.1.0
Runtime Dependencies
-
@angular/common -
@angular/core -
@angular/platform-browser -
@molecule/app-angular -
@molecule/app-i18n -
@molecule/app-logger -
@molecule/app-ui -
@molecule/app-ui-angular -
The fallback UI styles itself via
getClassMap()— if no ClassMap is bonded the boundary itself throws while rendering the fallback. EnsuresetClassMap()runs during bootstrap, before anything can error. -
There is no retry/reload action — the fallback is a static message (key
error.unknown). Wrap or fork when you need a recovery button. -
The boundary catches RENDER errors only — not event handlers, async code, or server-side rendering errors.
-
Projected content is created by the parent's view, outside the boundary's catch: guard a route component by passing it as the
contentTemplateRefinput instead. -
The fallback translates through
useTranslation(), so it re-renders in the new language after a locale switch. No providers are required: outside them it reads the bonded@molecule/app-i18nprovider, and without locale registration it falls back to English. Translations:@molecule/app-locales-root-error-boundary.
Translations
Translation strings are provided by @molecule/app-locales-root-error-boundary.