Title: Narrow the scope of the CUSTOM_ELEMENTS_SCHEMA schema · Issue #62484 · angular/angular · GitHub
Open Graph Title: Narrow the scope of the CUSTOM_ELEMENTS_SCHEMA schema · Issue #62484 · angular/angular
X Title: Narrow the scope of the CUSTOM_ELEMENTS_SCHEMA schema · Issue #62484 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? @angular/core (and @angular/compiler?) Description Currently, when using custom elements (e.g., Web Components) within an Angular application, developers must decla...
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? @angular/core (and @angular/compiler?) Description Currently, when using custom elements (e.g., Web Components) within an An...
X Description: Which @angular/* package(s) are relevant/related to the feature request? @angular/core (and @angular/compiler?) Description Currently, when using custom elements (e.g., Web Components) within an An...
Opengraph URL: https://github.com/angular/angular/issues/62484
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Narrow the scope of the CUSTOM_ELEMENTS_SCHEMA schema","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\n`@angular/core` (and `@angular/compiler`?)\n\n### Description\n\nCurrently, when using custom elements (e.g., Web Components) within an Angular application, developers must declare CUSTOM_ELEMENTS_SCHEMA either at the module level (e.g., NgModule.schemas) or component level (@Component.schemas). This global declaration effectively tells the Angular compiler to ignore any unknown elements within the entire scope, which can lead to a less strict template validation than desired, as it disables validation for all unknown elements, even those not intended to be custom elements.\n\nIt is of course possible to create small components that have the CUSTOM_ELEMENTS_SCHEMA. However, it is more difficult to maintain the quality of those templates over time. A pull request with only a HTML change would not show the schema that applies.\n\nThis proposal aims to introduce a mechanism to apply the CUSTOM_ELEMENTS_SCHEMA only to a specific, localized scope within an Angular template, leveraging the new @-prefixed control flow syntax. This would allow developers to precisely define where custom elements are expected, thus maintaining stricter template validation for the rest of the template and improving developer experience by reducing unnecessary global declarations.\n\n### Proposed solution\n\nI would like to propose a syntax to allow custom elements within a defined scope of a component template.\n\nThe syntax would look like this:\n```HTML\n@schema(CUSTOM_ELEMENTS_SCHEMA) {\n\u003cfluent-card class=\"custom\">\n \u003cfluent-progress value=\"64\">\u003c/fluent-progress>\n @schema(ANGULAR_DEFAULT_SCHEMA) {\n \u003capp-example>This component should still exist\u003c/app-example>\n }\n\u003c/fluent-card>\n}\n```\nThis way, you can define blocks within a template where a schema applies. In this proposal ANGULAR_DEFAULT_SCHEMA would refer to the schema that Angular applies by default if no other schema is defined. The example shows how you can nest this syntax to apply different schema's to nested HTML in the template.\n\nThe schema should be provided as a value.\n\nBy defining the schema within the template, it's less likely that the applied schema is overlooked, and it introduces enough flexibility to still apply validation where that is desired.\n\n### Alternatives considered\n\nHaving block scopes makes the template more verbose. I did consider having element scoped schema's, for example:\n```HTML\n\u003cfluent-card class=\"custom\" @schema=\"CUSTOM_ELEMENTS_SCHEMA\">\n \u003cfluent-progress value=\"64\" @schema=\"CUSTOM_ELEMENTS_SCHEMA\" />\n \u003capp-example>This component should still exist\u003c/app-example>\n\u003c/fluent-card>\n```\n\nBut having the block scope notation leaves no questions about the scope of the schema.\n\nAlternatively I did consider a notation like the one below, but I feel it's just difficult to read (and the element name could become a variable, with potential complex results):\n\n```HTML\n\u003cng-element ngElementName=\"fluent-card\" class=\"custom\">\n \u003capp-example>This component still exists\u003c/app-example>\n\u003c/ng-element>\n```\n\nOptionally it could be nice to also have this feature as a structural directive (*ngSchema=\"CUSTOM_ELEMENTS_SCHEMA\"), similar to how `@if` has an *ngIf alternative. But since there is no *ngLet, I considered to leave this scenario out of the proposal.\n\n---\n\nAlternatively a more adaptable schema could be considered:\n```\nschemas: [REGEX_SCHEMA(/^fluent\\-/i)]\n```\nHowever, this could lead to complex regular expressions or a regex that could degrade performance.\n\n---\n\nIt is of course possible to create small components that have the CUSTOM_ELEMENTS_SCHEMA. However, it is more difficult to maintain the quality of those templates over time. A pull request with only a HTML change would not show the schema that applies, leading the reviewer to assume that the used element names are correct.","author":{"url":"https://github.com/p-b-4","@type":"Person","name":"p-b-4"},"datePublished":"2025-07-05T19:07:39Z","url":"https://github.com/angular/angular/issues/62484"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:196f618b-99a2-9c43-5b7e-4f7d2c2e2189 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D7D0:EA09B:158E6B1:1C8FB71:6B013450 |
| html-safe-nonce | f49f611a980e5c68aec359157c7902b3376811d8d3ccbc3afd0fee1298277dee |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEN0QwOkVBMDlCOjE1OEU2QjE6MUM4RkI3MTo2QjAxMzQ1MCIsInZpc2l0b3JfaWQiOiI5MTAwMjY5Njg2MDEyMDY0ODQ4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | dd84323265efe4841757670a67527fb83102519e70d50dd3ee970aa4bcc476e6 |
| hovercard-subject-tag | issue:3205444677 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/62484/issue_layout |
| twitter:image | https://opengraph.githubassets.com/844b41168d766c2a4661e1fda270e5c9f35202dce39fe392f0e822e1716c995c/angular/angular/issues/62484 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/844b41168d766c2a4661e1fda270e5c9f35202dce39fe392f0e822e1716c995c/angular/angular/issues/62484 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? @angular/core (and @angular/compiler?) Description Currently, when using custom elements (e.g., Web Components) within an An... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | p-b-4 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width