angular / angular/components

*reduce* need for displayWith function on mat-autocomplete

オープン
#8,436 コメント 17 件 リアクション 10 件 担当者 0 名 GitHub で見る
area: material/autocomplete feature needs: discussion P4
主要言語
TypeScript
スター
25k
フォーク
6.8k
平均マージ
1日 8時間
マージ済み PR(30日)
91

説明

#### Bug, feature request, or proposal:
Proposal

#### What is the expected behavior?
A simple way to display the selected autocomplete value in an input field.

#### What is the current behavior?
Currently when you setup an autocomplete and bind a [value] to the , the autocomplete displays the value UNLESS you assign a displayWith function. However, it makes no sense to me to default to showing the [value] since that is intended to be the behind-the-scenes value, not the displayValue. If we simply default to displaying the viewValue somehow, we would no longer need a displayWith function, and that would eliminate numerous other headaches reported in other issues on this forum.

#### What are the steps to reproduce?
Providing a StackBlitz/Plunker (or similar) is the *best* way to get the team to see your issue.

Plunker starter (using on `@master`): https://goo.gl/uDmqyY

StackBlitz starter (using latest `npm` release): https://goo.gl/wwnhMV

This proposal relies on an understanding of the typical autocomplete implementation e.g. here: https://plnkr.co/edit/W9vdWaGcoG90LKM8hHgI?p=preview

#### What is the use-case or motivation for changing an existing behavior?
displayWith function has numerous issues reported. For my purpose I see it as a potential blocker to generating dynamic forms in particular, for reasons i'm glad to detail if need be but I'll spare at this time.

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?

#### Is there anything else we should know?
i'm guessing the displayWith function was created in the first place to address a legitimate challenge. Namely, the autocomplete control needs a way to know what the displayValue is.

so in the demo example here:

```


None
{{ state.name }}

```
the displayValue is state.name. Perhaps the new syntax that requires no displayValue would be like this:

```


None

```
Such a design would continue to allow flexibility to assign the whole object or a particular field to the [value]..which is important to various use cases out there.

I don't see any downside to eliminating the displayWith function as long as the viewValue is always shown I doubt people would care.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まずリンクされている Plunker と StackBlitz の例を実行して、現在の autocomplete の動作を再現し、提案された代替案を比較します。選択した値が displayWith を必要とせずにその viewValue を表示でき、なおかつ異なる基盤となる値を使用できるようになれば、作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。