From 6cf2dd22034a3ee5e6b91392329a8ababc19a21a Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 23 May 2019 16:50:18 +0200 Subject: [PATCH] chore: fix mdc-checkbox not working with ivy Fixes that the `mdc-checkbox` prototype does not work properly with Ivy as there are component inputs which are commonly set programmatically but do not mark the checkbox as dirty. This surfaced in one of the checkbox tests because with Ivy, calling `markForCheck` from within the `ngAfterViewInit` lifecycle hook has basically no effect while View Engine keeps the component dirty. This caused a checkbox test failure because the test just assigned the value of the `MatCheckbox#checked` property and called `detectChanges` afterwards. Since the component is not marked as dirty due to the aforementioned Ivy difference, the component will not be checked and updated. In order to fix the test we just mark the component for check in the input setters (similarly to how we do it for other inputs of `MatCheckbox` such as `disabled`). --- src/material-experimental/mdc-checkbox/checkbox.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/material-experimental/mdc-checkbox/checkbox.ts b/src/material-experimental/mdc-checkbox/checkbox.ts index a36d19be9d9..7dca953aeaa 100644 --- a/src/material-experimental/mdc-checkbox/checkbox.ts +++ b/src/material-experimental/mdc-checkbox/checkbox.ts @@ -120,6 +120,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess } set checked(checked) { this._checked = coerceBooleanProperty(checked); + this._changeDetectorRef.markForCheck(); } private _checked = false; @@ -135,6 +136,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess } set indeterminate(indeterminate) { this._indeterminate = coerceBooleanProperty(indeterminate); + this._changeDetectorRef.markForCheck(); } private _indeterminate = false; @@ -156,6 +158,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess } set required(required) { this._required = coerceBooleanProperty(required); + this._changeDetectorRef.markForCheck(); } private _required = false;