Title: Add ability to update secondary signal when input signal changes · Issue #54985 · angular/angular · GitHub
Open Graph Title: Add ability to update secondary signal when input signal changes · Issue #54985 · angular/angular
X Title: Add ability to update secondary signal when input signal changes · Issue #54985 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? core Description I have created a "multi select" component where a user can select any number of choices from a given list. This list is added to the component with...
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? core Description I have created a "multi select" component where a user can select any number of choices from a given list. ...
X Description: Which @angular/* package(s) are relevant/related to the feature request? core Description I have created a "multi select" component where a user can select any number of choices from a gi...
Opengraph URL: https://github.com/angular/angular/issues/54985
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add ability to update secondary signal when input signal changes","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\ncore\n\n### Description\n\nI have created a \"multi select\" component where a user can select any number of choices from a given list. This list is added to the component with an input signal. The selected options are stored in a WritableSignal as the user selects them. If the list of choices is updated from outside the component by the template embedding it the list of selected values need to be reset. I have not found a good way of doing this with signals whereas this was easily possible with ngOnChanges and the old `@Input` decorator.\r\n\r\nThe documentation warns against writing to signals in an effect so using an effect to do this does not seem like the best idea.\r\n\r\n```ts\r\n@Component({\r\n selector: 'app-multi-select-group',\r\n templateUrl: './multi-select-group.component.html',\r\n})\r\nexport class MultiSelectGroupComponent {\r\n // issue is here\r\n public options = input\u003cArray\u003cMultiSelectGroupOption>>([]); // \u003c- when this changes selectedItems needs to be reset\r\n public selectedItems = signal\u003cArray\u003cMultiSelectGroupOption>>([]);\r\n\r\n @Output() // ignore that I'm using the old API here Webstorm cannot deal with output signals properly yet\r\n public selectionChange = new EventEmitter\u003cArray\u003cMultiSelectGroupOption>>();\r\n\r\n public constructor() {\r\n effect(() => {\r\n this.selectionChange.emit(this.selectedItems());\r\n });\r\n }\r\n\r\n public selectItem(item: MultiSelectGroupOption): void {\r\n this.selectedItems.set([...selectedItems, item]);\r\n }\r\n}\r\n```\r\n\n\n### Proposed solution\n\nAdd an option to the input signal to specify a function that can do writes to other signals once the component input changes.\n\n### Alternatives considered\n\nThe alternative I could think of would be a adding a way to completely reset a component once a specific input signal changes.","author":{"url":"https://github.com/RaederDev","@type":"Person","name":"RaederDev"},"datePublished":"2024-03-21T21:51:39Z","url":"https://github.com/angular/angular/issues/54985"}
| 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:5a96a320-1d75-fbc3-92f0-3335eeac8f5d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8CAE:1D20B7:374FAAE:460A924:6B021F5A |
| html-safe-nonce | 5fd991bb297e9a42579839e3562aff8465af24a9d462bc216768f2801a2533d3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0FFOjFEMjBCNzozNzRGQUFFOjQ2MEE5MjQ6NkIwMjFGNUEiLCJ2aXNpdG9yX2lkIjoiNjI0MjcwNDQ5MzczODMzNjA5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 393088c4bd119a9393fa8deb132af1fb19079ef2d68f5862ed5beb07b5a6f5df |
| hovercard-subject-tag | issue:2201256462 |
| 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/54985/issue_layout |
| twitter:image | https://opengraph.githubassets.com/70fa18af86e75eb834d24a4c31deaae5a0b06945fe88ce638b223f504709f4c5/angular/angular/issues/54985 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/70fa18af86e75eb834d24a4c31deaae5a0b06945fe88ce638b223f504709f4c5/angular/angular/issues/54985 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? core Description I have created a "multi select" component where a user can select any number of choices from a given list. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RaederDev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width