Title: Make built-in validator directives standalone · Issue #56226 · angular/angular · GitHub
Open Graph Title: Make built-in validator directives standalone · Issue #56226 · angular/angular
X Title: Make built-in validator directives standalone · Issue #56226 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? @angular/forms Description I am building a set of configurable form field components that uses the directive composition API. I want to reuse Angular's built-in val...
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? @angular/forms Description I am building a set of configurable form field components that uses the directive composition API...
X Description: Which @angular/* package(s) are relevant/related to the feature request? @angular/forms Description I am building a set of configurable form field components that uses the directive composition API...
Opengraph URL: https://github.com/angular/angular/issues/56226
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make built-in validator directives standalone","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\r\n\r\n@angular/forms\r\n\r\n### Description\r\n\r\nI am building a set of configurable form field components that uses the directive composition API. I want to reuse Angular's built-in validator directives to define what validators are applicable to each field without re-implementing them in each form field component. \r\n\r\n```ts\r\n@Component({\r\n standalone: true,\r\n selector: 'form-field[type=\"project-id\"]',\r\n imports: [MatFormFieldModule, MatInputModule, ReactiveFormsModule],\r\n template: `\r\n \u003cmat-form-field\u003e\r\n \u003cmat-label\u003eProject ID\u003c/mat-label\u003e\r\n \u003cinput matInput [formControl]=\"control\" /\u003e\r\n @if (control.hasError('required')) {\r\n \u003cmat-error\u003eProject ID is required\u003c/mat-error\u003e\r\n }\r\n \u003c/mat-form-field\u003e\r\n `,\r\n hostDirectives: [{\r\n directive: RequiredValidator, // TS-992014: Host directive RequiredValidator must be standalone\r\n inputs: ['required']\r\n }, {\r\n directive: FormFieldDirective // implements ControlValueAccessor\r\n }],\r\n providers: provideFormField(ProjectIdFieldComponent),\r\n})\r\nexport class ProjectIdFieldComponent {\r\n control = new FormControl();\r\n}\r\n```\r\n\r\n```html\r\n\u003cform-field type=\"project-id\" [(ngModel)]=\"projectId\" [required]=\"required\" /\u003e\r\n```\r\n\r\nRelated issue: https://github.com/angular/angular/issues/51248\r\n\r\n### Proposed solution\r\n\r\nAdd the standalone flag to existing validator directives.\r\n\r\n### Alternatives considered\r\n\r\nI am currently converting these to standalone directives myself.\r\n\r\n```ts\r\n@Directive({\r\n standalone: true,\r\n providers: [provideValidator(StandaloneRequiredValidator)]\r\n})\r\nexport class StandaloneRequiredValidator extends RequiredValidator {}\r\n\r\n...etc\r\n```\r\n\r\n```ts\r\n@Component({\r\n hostDirectives: [{\r\n directive: StandaloneRequiredValidator, // now it works\r\n inputs: ['required']\r\n }],\r\n})\r\nexport class ProjectIdFieldComponent {}\r\n```\r\n","author":{"url":"https://github.com/chronospatian","@type":"Person","name":"chronospatian"},"datePublished":"2024-06-02T22:01:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/56226/angular/issues/56226"}
| 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:922513a9-226e-90f5-67fa-b5de2824b812 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93E2:C2FFC:2268DA8:2C464E0:6974AC5D |
| html-safe-nonce | 255e28be82a4b71367318f8887786f3552b2d2bfad257ae2e04e672d5b28db94 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0UyOkMyRkZDOjIyNjhEQTg6MkM0NjRFMDo2OTc0QUM1RCIsInZpc2l0b3JfaWQiOiI1NTI4NDAxNDY5MDMyOTM0NDkzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 04d347182d78528ea6952bd9817ebf5104b139c0b1f6d34c113e32dd560e6d36 |
| hovercard-subject-tag | issue:2329882712 |
| 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/56226/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a52b916555f9a954096025753582aaab7800161b946ab6e7494ae95f7a83654a/angular/angular/issues/56226 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a52b916555f9a954096025753582aaab7800161b946ab6e7494ae95f7a83654a/angular/angular/issues/56226 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? @angular/forms Description I am building a set of configurable form field components that uses the directive composition API... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | chronospatian |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4a4bf5f4e28041a9d2e5c107d7d20b78b4294ba261cab243b28167c16a623a1f |
| 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 | 488b30e96dfd057fbbe44c6665ccbc030b729dde |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width