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

未关闭
#14,974 9 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看
area: material/autocomplete feature needs: discussion P3
主要语言
TypeScript
星标
25k
派生
6.8k
平均合并
1 天 8 小时
30 天内合并 PR
91

描述

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.

贡献指南

打开贡献指南

调研方向

从链接的 Angular Material autocomplete 文档开始,特别是关于设置单独的控件值和显示值的部分,并将其与 issue 中的 user object 示例进行比较。当 autocomplete 在选择后能够显示 user.name,同时提交 user.id 而不是名称或整个对象时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。