Support for setting option's control value to be a property of object and option's display value to be another property of the object
- Langage dominant
- TypeScript
- Étoiles
- 25k
- Forks
- 6.8k
- Merge moyen
- 1 j 8 h
- PR mergées (30 j)
- 91
Description
I know that if we want the option's control value (what is saved in the form) to be different than the option's display value (what is displayed in the text field), we'll need to set the **displayWith** property on our autocomplete element. as explained here:
https://material.angular.io/components/autocomplete/overview#setting-separate-control-and-display-values
Suppose we have a user object like `{ id: 1, name: 'Abc' }`.
What if we want the option's control value (what is saved in the form) to be **user.id** and option's display value (what is displayed in the actual text field) to be **user.name**?
In my case I want to display a list of users in autocomplete options and when user selects a user, I want to display the selected user name on the user screen but when the form is submitted, I just want user.id to be posted to the server not user.name and not complete user object.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par la documentation liée d’Angular Material sur l’autocomplétion, en particulier la section consacrée à la définition de valeurs distinctes pour le contrôle et l’affichage, et comparez-la avec l’exemple de user object dans l’issue. Le travail est considéré comme terminé lorsqu’une autocomplétion peut afficher user.name après la sélection tout en envoyant user.id plutôt que le nom ou l’objet entier.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- angular, typescript
- Domaine
- frontend
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100