Skip to content

Commit

Permalink
fix(material/datepicker): pass correct inject flags to injector (#22665)
Browse files Browse the repository at this point in the history
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.

angular/angular#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 7367823)
  • Loading branch information
crisbeto authored and andrewseguin committed May 18, 2021
1 parent 68b9c67 commit f1e109c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/material/datepicker/date-range-input-parts.ts
Expand Up @@ -102,7 +102,8 @@ abstract class MatDateRangeInputPartBase<D>
// 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;
Expand Down

0 comments on commit f1e109c

Please sign in to comment.