From f1e109c06a066efecdb3568aaa4e63456cd287c3 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 18 May 2021 21:49:05 +0200 Subject: [PATCH] fix(material/datepicker): pass correct inject flags to injector (#22665) 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. (cherry picked from commit 73678234470b58d7a08de7446443c3cf5d761fca) --- 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;