From 3e8d8924fb23d9aef58cb411fa4aec1fd9b242e8 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 11 May 2021 19:26:37 +0200 Subject: [PATCH] fix(material/datepicker): pass correct inject flags to injector We have a call to `Injector.get` in the date range input which is supposed to fall back to `null` if the value doesn't resolve, however we're missing the `Optional` flag. It works by accident at the moment, because the inject flags aren't actually being passed through by the framework. https://github.com/angular/angular/pull/41592 is supposed to fix the framework issue, but their CI will break due to our usage. These changes fix our usage in order to unblock the framework PR. --- src/material/datepicker/date-range-input-parts.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/material/datepicker/date-range-input-parts.ts b/src/material/datepicker/date-range-input-parts.ts index f9b92e555cf7..910f47869a50 100644 --- a/src/material/datepicker/date-range-input-parts.ts +++ b/src/material/datepicker/date-range-input-parts.ts @@ -102,7 +102,8 @@ abstract class MatDateRangeInputPartBase // itself. Usually we can work around it for the CVA, but there's no API to do it for the // validator. We work around it here by injecting the `NgControl` in `ngOnInit`, after // everything has been resolved. - const ngControl = this._injector.get(NgControl, null, InjectFlags.Self); + // tslint:disable-next-line:no-bitwise + const ngControl = this._injector.get(NgControl, null, InjectFlags.Self | InjectFlags.Optional); if (ngControl) { this.ngControl = ngControl;