angular / angular/components

Feature: Possibility to make the [displayWith] of Autocomplete more flexible

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

説明

#### Bug, feature request, or proposal:
Feature Request.

#### What is the expected behavior?
I expect `[displayWith]` to give me back the whole `object` so I can treat what property I can return to `display` (doesn't it make sense)?

#### What is the current behavior?
Actually `[displayWith]` is too limited.

Ex:

I have the following variable that gets the content from API:

```
this.myObs = this..();
```

That's the content coming from back-end:

```
[
{ id: 1, name: 'anyName' },
{ id: 2, name: 'xxx' }
];
```

In template I have:

```


{{ obj.name }}

```
Since, I'm binding the md-option to `id`, `[displayWith]` just gives me the value of `id` while I was expecting at least the `full object` so I can return the `name`, for example.

**Workarounds:**

1- Subscribe to the observables and store in arrays.

**Problem 1:** You'll have to loop through the array **everytime** that an option is selected to return the desired property.

**Problem 2:** Imagine that I have more than 10 autocomplete (my case), I'll have to create 10 variables and subscribe them all while I could simply use the `async` pipe (as I'm doing) and, consequently I wouldn't need to subscribe in nothing.

2 - Bind the full object to ``, so `[displayWith]` will give me back the whole object.

**Problem:** If your API expects a single property (in my case back-end expects only the id), before submits the form, you'll have to change **the whole** content of form that was stored as object to id.

#### What are the steps to reproduce?

Providing a Plunker (or similar) is the *best* way to get the team to see your issue.
Plunker template: https://goo.gl/DlHd6U

#### What is the use-case or motivation for changing an existing behavior?
-

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Material 2.0.0-beta.6

#### Is there anything else we should know?
The workarounds can be used? Ofc they can, however it'd be really better if Material2 could provide a better solution for this.

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

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

調査の方向性

まず、displayWith と md-option の値に関する Angular Material のオートコンプリートの動作を確認します。非同期のオプションリスト、id 値のオプション、表示関数を使用して例を再現します。手動のサブスクリプションを必要とせず、送信前にフォームの値を置き換えることもなく、要求されたオブジェクト対応の表示動作が定義され、検証されていれば完了です。

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

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
28/100

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

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