angular / angular/components

form-field: support swapping various child components with ngIf

Đang mở
#7,737 11 bình luận 14 reaction 0 người được giao Xem trên GitHub
area: material/form-field feature P3
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:

I recently ran into a bug that `mat-hint` threw an error when its corresponding `matInput` is inserted conditionally. E.g. take the following template:

```




Some hint.

```
Note that the only reason inputs are inserted conditionally here is because the placeholder text is different depending on the condition.

This will throw the following error:

```
app.component.html:7 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'null'. Current value: 'mat-hint-0'.
at new d (VM8254 zone.min.js:1)
at viewDebugError (VM7606 core.umd.js:8466)
at expressionChangedAfterItHasBeenCheckedError (VM7606 core.umd.js:8444)
at checkBindingNoChanges (VM7606 core.umd.js:8608)
at checkNoChangesNodeDynamic (VM7606 core.umd.js:12515)
at checkNoChangesNode (VM7606 core.umd.js:12464)
at debugCheckNoChangesNode (VM7606 core.umd.js:13241)
at debugCheckRenderNodeFn (VM7606 core.umd.js:13181)
at Object.eval [as updateRenderer] (VM7993 AppComponent.ngfactory.js:78)
at Object.debugUpdateRenderer [as updateRenderer] (VM7606 core.umd.js:13163)
at checkNoChangesView (VM7606 core.umd.js:12283)
at callViewAction (VM7606 core.umd.js:12650)
at execEmbeddedViewsAction (VM7606 core.umd.js:12628)
at checkNoChangesView (VM7606 core.umd.js:12282)
at callViewAction (VM7606 core.umd.js:12650)
```
This is not a problem when the input is not inserted conditionally but rather placed in the template right away. **I'm not sure if that is by design or not** but it caused me some hours of debugging until I realised it was the combination of `mat-hint` inside a `mat-form-field` whom\s `matInput` is rendered using `*ngIf`.

#### What is the expected behavior?

I expected this to just work, but again, maybe this is by design but then we should document somewhere that `matInput`s aren't allowed to be inserted using structural directives.

#### What is the current behavior?

Described above.

#### What are the steps to reproduce?

Here's a plunk that reproduces the error: http://plnkr.co/edit/MrUvFVKIW1BoX9d96eeu?p=preview

Simply check the console.

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

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

I'm using `@angular/material` version `2.0.0-beta.11` but the plunk uses the latest version. Unfortunately I can't tell if this error has been thrown in older versions as well.

#### Is there anything else we should know?

Yeah, you're all doing an amazing job. Thanks for that.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với ví dụ trong template của issue và Plunker được liên kết, tái hiện ExpressionChangedAfterItHasBeenCheckedError khi các phần tử con matInput được chèn bằng *ngIf cùng với mat-hint. Đọc hành vi của mat-form-field, matInput và mat-hint liên quan đến các thay đổi có điều kiện của phần tử con. Hoàn tất có nghĩa là việc hoán đổi các inputs theo điều kiện không còn gây ra lỗi được báo cáo và trường hợp đã tái hiện có độ bao phủ kiểm thử.

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
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.