Pattern: What is the correct pattern for Angular Elements (@angular/e...

Documentation for Sessions

🎨 Pattern: What is the correct pattern for Angular Elements (@angular/e...

Date: 2026-03-26
Time: 15:19:34 UTC
Session: gspace1-271.4
Agent: angular
Confidence: 98%
Status: ✅ Documented


📋 Decision Context

Question:

What is the correct pattern for Angular Elements (@angular/elements) to receive HTML attribute values?

Task: Not specified


🎯 Decision Made

Chosen:

Use @Input() decorator setters backed by private signals — NOT signal inputs (input()). createCustomElement() only introspects @Input() decorators to register observedAttributes on the Custom Element. Signal inputs are invisible to the CE attribute mapping. Pattern: @Input() set data(v: string) { this._data.set(v); }

Options Considered:


💭 Reasoning

Angular 20's createCustomElement() uses ComponentFactoryResolver to discover inputs. It only sees @Input() decorator metadata, not the newer input() signal API. When using signal inputs, observedAttributes returns [] and no HTML attributes reach the component. Discovered via browser testing: SVG charts rendered empty containers because data() signal was never set. Fix confirmed: switching to @Input() setter + backing signal made all attributes work. This is an Angular framework limitation — createCustomElement hasn't been updated for signal inputs.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation