Feature: Possibility to make the [displayWith] of Autocomplete more flexible
- Ngôn ngữ chính
- TypeScript
- Star
- 25k
- Fork
- 6.8k
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 91
Mô tả
#### 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.
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách xem xét hành vi autocomplete của Angular Material liên quan đến displayWith và các giá trị md-option. Tái hiện ví dụ bằng cách sử dụng một danh sách tùy chọn bất đồng bộ, một tùy chọn có giá trị id và một hàm hiển thị. Công việc được xem là hoàn tất khi hành vi hiển thị nhận biết đối tượng được yêu cầu đã được định nghĩa và xác minh mà không cần các subscription thủ công hoặc thay thế giá trị biểu mẫu trước khi gửi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- angular, typescript
- Lĩnh vực
- frontend
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 28/100