Install
import { provideWrMeta, WrMeta } from 'ngwr/meta';
bootstrapApplication(AppComponent, {
providers: [
provideWrMeta({
titleTemplate: '{{ title }} · NGWR',
og: { siteName: 'NGWR', type: 'website' },
twitter: { card: 'summary_large_image', creator: '@thekhegay' },
}),
],
});Push / pop
private readonly meta = inject(WrMeta);
ngOnInit() {
const handle = this.meta.push({
title: 'Pricing',
description: 'Plans for every team.',
og: { image: '/og/pricing.png' },
});
this.destroyRef.onDestroy(() => handle.pop());
}Directive form
<!-- Auto-pops on destroy. Perfect for route components. -->
<div [wrMeta]="{ title: 'Pricing', description: 'Plans for every team.' }">
…
</div>Reactive title (i18n)
bind() runs its factory inside an effect — read WrI18n.t() (or any signal) and the <head> re-renders on every locale switch, with no manual re-set().
private readonly meta = inject(WrMeta);
private readonly i18n = inject(WrI18n);
ngOnInit() {
// `i18n.t(...)` tracks the active locale, so the document title
// re-renders automatically whenever the language changes — no
// manual re-set on `NavigationEnd` or a locale subscription.
const handle = this.meta.bind(() => ({
title: this.i18n.t('home.title'),
description: this.i18n.t('home.description'),
}));
this.destroyRef.onDestroy(() => handle.pop());
}Why ngwr provides this
Angular's Title and Meta are low-level setters — every app rebuilds the same canonical-URL / OpenGraph / Twitter-card plumbing on top. WrMeta is that layer, with a title template and per-route overrides.
API
| Name | Description | Type | Default |
|---|---|---|---|
set(config) | Replace the current top of the stack. | (config: WrMetaConfig) => void | — |
push(config) | Push a new layer. Returns { pop } — call .pop() to remove. | (config: WrMetaConfig) => WrMetaHandle | — |
bind(factory) | Reactive layer — re-applies whenever a signal read inside factory changes (e.g. WrI18n.t() on locale switch). Returns { pop }. | (factory: () => WrMetaConfig) => WrMetaHandle | — |
pop() | Pop the most recently pushed layer. | () => void | — |
reset() | Clear all overrides, restore defaults registered via provideWrMeta. | () => void | — |
current() | Snapshot of the resolved metadata currently applied to <head>. | () => Readonly<WrMetaConfig> | — |
[wrMeta] | Directive: pushes on init, re-pushes on input change, pops on destroy. | WrMetaConfig | — |