Title: Multiple template for single component · Issue #61305 · angular/angular · GitHub
Open Graph Title: Multiple template for single component · Issue #61305 · angular/angular
X Title: Multiple template for single component · Issue #61305 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? core Description Currently, Angular requires templateUrl in the @component decorator to be a statically analyzable string. This restriction prevents developers from...
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? core Description Currently, Angular requires templateUrl in the @component decorator to be a statically analyzable string. T...
X Description: Which @angular/* package(s) are relevant/related to the feature request? core Description Currently, Angular requires templateUrl in the @component decorator to be a statically analyzable string. T...
Opengraph URL: https://github.com/angular/angular/issues/61305
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Multiple template for single component","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\ncore\n\n### Description\n\nCurrently, Angular requires templateUrl in the @Component decorator to be a statically analyzable string. This restriction prevents developers from dynamically choosing between multiple HTML templates based on conditions such as screen size (mobile vs desktop) or build-time environment flags.\n\n### Proposed solution\n\nModern applications often need to provide completely different layouts for mobile and desktop views. While responsive design using CSS works for simple changes, larger structural differences (like different component trees, layout structures, or interactions) require different templates altogether.\n```\n@Component({\n selector: 'app-guest',\n templateUrl: environment.isMobile\n ? './guest.component.mobile.html'\n : './guest.component.desktop.html',\n styleUrls: ['./guest.component.scss'],\n})\nexport class GuestComponent {}\n```\nHowever, this currently causes a compilation error:\n`templateUrl must be a string. Value could not be determined statically.`\n\n\n### Alternatives considered\n\nAllow templateUrl to accept a function or allow Angular’s AOT compiler to evaluate environment variables (e.g., from environment.ts) statically during build time. For example:\n\n```\n@Component({\n selector: 'app-guest',\n templateUrl: selectTemplateByEnv(), // evaluated at build time only\n})\nexport class GuestComponent {}\n\nfunction selectTemplateByEnv() {\n return environment.isMobile\n ? './guest.component.mobile.html'\n : './guest.component.desktop.html';\n}\n```\nAlternatively, Angular can support:\n```\ntemplateUrl: environment.useMobileTemplate\n ? './guest.component.mobile.html'\n : './guest.component.desktop.html'\n\n```","author":{"url":"https://github.com/AftabUddin9","@type":"Person","name":"AftabUddin9"},"datePublished":"2025-05-13T12:09:53Z","url":"https://github.com/angular/angular/issues/61305"}
| 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:f38ef398-9d16-0df9-0dc7-c97ba8a9e33b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E312:10DACD:9E0426:D3A4BD:6B00E8C2 |
| html-safe-nonce | a9023eabd2f0cfea9e4f1fb7f09ebd5a1e3062e8c14bf56674de06a2c45a4a7a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzEyOjEwREFDRDo5RTA0MjY6RDNBNEJEOjZCMDBFOEMyIiwidmlzaXRvcl9pZCI6IjM1MTA2NTY5NDYxNDExOTQ0MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 98d189c35827527f18650eab0403dec24307c6ff8c9d26e10cb1a5a17723dd6c |
| hovercard-subject-tag | issue:3059847549 |
| 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/61305/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1936ace8a9f2c7714ca5f9b16632507ec13d6985942199379da6da2716ad3908/angular/angular/issues/61305 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1936ace8a9f2c7714ca5f9b16632507ec13d6985942199379da6da2716ad3908/angular/angular/issues/61305 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? core Description Currently, Angular requires templateUrl in the @component decorator to be a statically analyzable string. T... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AftabUddin9 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width