From acc885479bac17f409d9fa94e4894a240c474f43 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sat, 1 Sep 2018 11:37:12 +0200 Subject: [PATCH] fix(stepper): intl provider not being picked up in lazy-loaded modules Along the same lines as #7988 and #7895. Fixes the consumer-provided `MatStepperIntl` instance not being picked up inside lazy-loaded modules. Fixes #12904. --- src/lib/stepper/stepper-intl.ts | 15 ++++++++++++++- src/lib/stepper/stepper-module.ts | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lib/stepper/stepper-intl.ts b/src/lib/stepper/stepper-intl.ts index a6a43b300b3f..9e0dab687036 100644 --- a/src/lib/stepper/stepper-intl.ts +++ b/src/lib/stepper/stepper-intl.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Injectable} from '@angular/core'; +import {Injectable, Optional, SkipSelf} from '@angular/core'; import {Subject} from 'rxjs'; @@ -22,3 +22,16 @@ export class MatStepperIntl { /** Label that is rendered below optional steps. */ optionalLabel: string = 'Optional'; } + + +/** @docs-private */ +export function MAT_STEPPER_INTL_PROVIDER_FACTORY(parentIntl: MatStepperIntl) { + return parentIntl || new MatStepperIntl(); +} + +/** @docs-private */ +export const MAT_STEPPER_INTL_PROVIDER = { + provide: MatStepperIntl, + deps: [[new Optional(), new SkipSelf(), MatStepperIntl]], + useFactory: MAT_STEPPER_INTL_PROVIDER_FACTORY +}; diff --git a/src/lib/stepper/stepper-module.ts b/src/lib/stepper/stepper-module.ts index e74f3fbd19ce..163023728172 100644 --- a/src/lib/stepper/stepper-module.ts +++ b/src/lib/stepper/stepper-module.ts @@ -18,7 +18,7 @@ import {MatStepLabel} from './step-label'; import {MatHorizontalStepper, MatStep, MatStepper, MatVerticalStepper} from './stepper'; import {MatStepperNext, MatStepperPrevious} from './stepper-button'; import {MatStepperIcon} from './stepper-icon'; -import {MatStepperIntl} from './stepper-intl'; +import {MAT_STEPPER_INTL_PROVIDER} from './stepper-intl'; @NgModule({ @@ -54,6 +54,6 @@ import {MatStepperIntl} from './stepper-intl'; MatStepHeader, MatStepperIcon, ], - providers: [MatStepperIntl, ErrorStateMatcher], + providers: [MAT_STEPPER_INTL_PROVIDER, ErrorStateMatcher], }) export class MatStepperModule {}