Question presented to candidate:
"We want to use a design-system button built as a Web Component, <ds-button>, inside our Angular templates, and the build fails with 'ds-button is not a known element'. What is CUSTOM_ELEMENTS_SCHEMA, what exactly does it switch off, and what are the risks of adding it?"
What a strong answer should cover:
- Angular's compiler checks every element and property binding in a template against known components and the DOM schema; unknown ones fail the build with NG8001 (element) and NG8002 (property).
schemas: [CUSTOM_ELEMENTS_SCHEMA]on a component (or NgModule) tells it to accept any element with a dash in its name and any property on such elements, which is what Web Components look like.- Bindings then go straight to the element:
[value]sets a DOM property,(rate)listens to a DOM event, plain attributes stay attributes; the browser upgrades the element whencustomElements.defineruns. - Risk: it also silences typos and missing imports for dashed tags; scope it to the components that host Web Components, never app-wide.
NO_ERRORS_SCHEMAis broader still (any element, any property) and mostly a test shortcut. - Elements without a dash still error; the schema does not register or load anything.
- The reverse direction, Angular component as a Web Component, is
@angular/elementswithcreateCustomElement, which needs no schema in the Angular app that defines it.
Clarifying questions expected:
- "Is the Web Component library loaded and defined before our templates render?"
- "Are we consuming Web Components, or exposing Angular components to other frameworks?"
Code / implementation expected: Yes β a template using a custom element with property and event bindings under the schema.