Equivalent to react controlled-component
- Vorherrschende Sprache
- TypeScript
- Sterne
- 101k
- Forks
- 27.5k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 288
Beschreibung
# Feature Request
In React, the state be the “single source of truth” in [controlled components](https://reactjs.org/docs/forms.html#controlled-components)
but there is no equivalent feature in angular
### Relevant Package
`@angular/form`
### Description
DEMO 1:
- in React
https://stackblitz.com/edit/react-ts-kyqxmj?file=index.tsx
type something in the `input`, and the input value won't change, the state be the single source of truth
- in Angular
https://stackblitz.com/edit/angular-ivy-sazmxc?file=src%2Fapp%2Fapp.component.ts
type something in the `input`, and the input will change, the state won't be the single source of truth
DEMO 2:
- in React
`click` -> `response` -> `true`
the view is always keeping the same as the state
https://stackblitz.com/edit/react-ts-zaolxq?file=index.tsx
- in Angular
`click` -> `true(the checkbox's inner state has changed and not matched with the outer state)` -> `server response` -> `update the inner state to false`
the view is not follow the state when you click it.
https://stackblitz.com/edit/angular-ivy-99wkuf?file=src%2Fapp%2Fapp.component.ts
### Describe the solution you'd like
support changing the form components to use controlled mode or not controlled mode
adding an option to ngModelOptions to support this feature
such as `[ngModelOptions]={controlled: true}`
ref #5184
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.