Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: MatStepperIntl custom implementation not injected #12904

Closed
frankvdb7 opened this issue Aug 30, 2018 · 5 comments · Fixed by #12934
Closed

bug: MatStepperIntl custom implementation not injected #12904

frankvdb7 opened this issue Aug 30, 2018 · 5 comments · Fixed by #12934
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@frankvdb7
Copy link

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Inject the custom provided CustomMatStepperIntl

What is the current behavior?

The default MatStepperIntl is used

What are the steps to reproduce?

  1. Provide CustomMatStepperIntl in app.module.ts
    { provide: MatStepperIntl, useClass: CustomMatStepperIntl }
  2. Make a lazy loaded module that imports MatStepperModule
  3. The default MatStepperIntl is injected instead (in the lazy loaded module)

What is the use-case or motivation for changing an existing behavior?

I want to translate specific labels for the stepper component as per global level and not by lazy loaded module level.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 6.1.4
Material 6.4.6

Is there anything else we should know?

The MatPaginatorIntl works as expected... Why should MatStepperIntl work different?

@crisbeto crisbeto assigned crisbeto and unassigned crisbeto Aug 30, 2018
@crisbeto
Copy link
Member

What does your CustomMatStepperIntl look like?

@frankvdb7
Copy link
Author

frankvdb7 commented Aug 31, 2018

In this case the constructor doesn't even get called:

@Injectable()
export class CustomMatStepperIntl extends MatStepperIntl implements OnDestroy {
  private onLangChange: Subscription;

  constructor(private translate: TranslateService) {
    super();

    this.onLangChange = this.translate.onLangChange.subscribe((e: LangChangeEvent) => {
      this.Init();
    });

    this.Init();
  }

  private async Init() {
    this.optionalLabel = await this.translate.get("Optional").toPromise();
    this.changes.next();
  }

  ngOnDestroy(): void {
    this.onLangChange.unsubscribe();
  }
}

@crisbeto
Copy link
Member

Can you set the injectable to be provided at the root and seeing if it helps? e.g. @Injectable({providedIn: 'root'})

@frankvdb7
Copy link
Author

I tried adding @Injectable({providedIn: 'root'}) but it doesn't seem to be making any difference.

If you look at the MatPaginatorModule that provides MatPaginatorIntl and MatStepperModule that provides MatStepperIntl, you'll see that the implementation of providing them are different. The MatPaginatorModule / MatPaginatorIntl seem to be using a factory.

@crisbeto crisbeto self-assigned this Sep 1, 2018
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent has pr labels Sep 1, 2018
crisbeto added a commit to crisbeto/material2 that referenced this issue Sep 1, 2018
Along the same lines as angular#7988 and angular#7895. Fixes the consumer-provided `MatStepperIntl` instance not being picked up inside lazy-loaded modules.

Fixes angular#12904.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants