Add 'compareWith' option to mat-radio-group just like mat-select
- 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: There is an issue with the mat-radio-group. If you use an object as the value for the form control the corresponding radio button is not checked. It only uses reference based comparison for checking which button should be highlighted.
I would like the ability to specify a comparison method to use while the mat-radio-group is deciding which item is selected. Just like how you can already specify a 'compareWith' method for a mat-select control.
#### What is the expected behavior?
If you use basic values it works as expected. Example [here](https://stackblitz.com/edit/angular-1shnoa-x1fwoc?file=app/radio-ng-model-example.ts). In this case the value is set to 1.1 and the 'one,one' button is selected.
#### What is the current behavior?
However when you use an array, it does not work. Example [here](https://stackblitz.com/edit/angular-1shnoa-dfc9q3?file=app/radio-ng-model-example.ts). In this case the value is set to [1,1] and none of the buttons are selected. Even though the form control's value is clearly shown to be [1,1].
#### What is the use-case or motivation for changing an existing behavior?
I am currently trying to dynamically generate a form based on some data given back from an API. The api gives me choices and a selected value to show by default.
`{
tag: 'radio button',
value: '[0,1]',
choices: [
{
tag: 'option 1',
value: [0,0]
},
{
tag: 'option 2',
value: [0,1]
}
]
}`
In the spec for mat-radio-group and mat-radio-button the value is of type any. So it should support any type of value I want to use.
The current mat-select control already possesses this feature and I would like to see it paralleled in the radio button control. [Here](https://stackblitz.com/edit/angular-1shnoa-bsju2l?file=app/radio-ng-model-example.ts) is an example of the select control with the 'compareWith' attribute. As you can see it selects the "one,one" value by default.
#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular: 5.2.6
@angular/material: 5.2.3
typescript: 2.4.2
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách so sánh các triển khai của mat-radio-group và mat-select cùng các spec liên quan, sử dụng các ví dụ StackBlitz được liên kết để tái hiện việc chọn giá trị đối tượng và mảng. Hoàn thành khi mat-radio-group hỗ trợ một phương thức compareWith có thể cấu hình để chọn giá trị và hành vi này được bao phủ bởi các spec của radio-group và radio-button.
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
- 35/100