question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug(MatTabGroup): StaticInjectorError thrown when using MatTabGroup with wrapper component

See original GitHub issue

Reproduction

See this Stackblitz

Create a component that includes a MatTabGroup whose MatTab come inside ng-content

<mat-tab-group #tabGroup>
     <ng-content></ng-content>
</mat-tab-group>

Expected Behavior

The MatTabGroup should not give an error, as it was the case with Angular 10 / Angular Material 10. See this stackblitz for a working example with Angular 10 / Angular Material 10

Actual Behavior

The following error is thrown:

Error: StaticInjectorError(AppModule)[MatTab -> InjectionToken MAT_TAB_GROUP]:
StaticInjectorError(Platform: core)[MatTab -> InjectionToken MAT_TAB_GROUP]:
NullInjectorError: No provider for InjectionToken MAT_TAB_GROUP!

Environment

  • Angular: 11.1.1
  • CDK/Material: 11.1.1
  • Browser(s): Tested in Chrome and Firefox
  • Operating System (e.g. Windows, macOS, Ubuntu): Tested on macOS and Ubuntu

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
Brutusncommented, Feb 26, 2021

I ‘fixed’ the issue by providing the MAT_TAB_GROUP token in the wrapper component:

providers: [
	{
		provide: MAT_TAB_GROUP,
		useValue: undefined,
	},
],
1reaction
crisbetocommented, Jun 18, 2021

Merging the fix itself isn’t that difficult, but releasing the changes and updating the docs takes a while.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Material Tabs not working with wrapper component
Using the components of MatTabModule directly works like a charm, whereas when using our custom components the projected content does not show ...
Read more >
Tabs - Angular Material
MatTabGroup. Material design tab-group component. Supports basic tab pairs (label + content) and includes animated ink-bar, keyboard navigation, ...
Read more >
Components Issue Mat Tab Group Wrapper Working With ...
Issue template for @angular/material.
Read more >
Implement Lazy Loading with Mat Tabs in Angular - Medium
ts file for the component we need to lazy load. Project Setup. Here, we set up our project. We will be using the...
Read more >
Create a dynamic tab component with Angular | juri.dev
Within our AppComponent we can now reference our tabs component ( <my-tabs> ) as well as the ng-template by using Angular's @ViewChild ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found