Angular cannot support the polymorphic 'as' prop pattern common in React and Vue due to its architecture. Angular is a template-compiled framework where the compiler generates static blueprint functions at build time, leaving the runtime with minimal DOM manipulation capabilities. Adding a dynamic element-casting API would require a more expressive runtime, leading to bundle bloat and slower parsing. As a workaround, Angular's attribute selectors allow attaching component behavior to existing HTML elements (e.g., `a[our-button]` or `button[our-button]`), achieving similar visual results without dynamic element creation.

5m read timeFrom playfulprogramming.com
Post cover image
Table of contents
Angular, the compiler Copy link Link copied!Angular, the tree Copy link Link copied!Angular, the runtime Copy link Link copied!Angular casting, the workaround Copy link Link copied!

Sort: