InterviewHubPRO
Section Overview
Q57

Question 57 of 283

Part 2: HttpClient, RxJS Observables & Angular Elements (36 - 62)

20%
Angular & Signals (283 Qs)•Part 2: HttpClient, RxJS Observables & Angular Elements (36 - 62)

What are the mapping rules between Angular component and custom element?

The Component properties and logic maps directly into HTML attributes and the browser's event system. Let us describe them in two steps,

  1. The createCustomElement() API parses the component input properties with corresponding attributes for the custom element. For example, component @Input('myInputProp') converted as custom element attribute my-input-prop.
  2. The Component outputs are dispatched as HTML Custom Events, with the name of the custom event matching the output name. For example, component @Output() valueChanged = new EventEmitter() converted as custom element with dispatch event as "valueChanged".

Practical Code Example

typescript
// Mapping Rules:
// 1. Angular @Input('title') -> HTML attribute / property 'title'
// 2. Angular @Output() valueChange -> Native CustomEvent('valueChange', { detail: val })