angular / angular/components

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

Offen
#14,974 9 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: material/autocomplete feature needs: discussion P3
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der verlinkten Angular Material-Dokumentation zur Autovervollständigung, insbesondere mit dem Abschnitt zum Festlegen getrennter Steuerungs- und Anzeigewerte, und vergleiche sie mit dem user object-Beispiel im Issue. Als erledigt gilt die Aufgabe, wenn eine Autovervollständigung nach der Auswahl user.name anzeigen kann, während user.id statt des Namens oder des gesamten Objekts übermittelt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.