-1

I have two module, ChatModule and LibraryModule and i want to import the ChatComponent inside of the LibraryComponent but im get this error

Error: Template parse errors:
'mat-tab' is not a known element:
1. If 'mat-tab' is an Angular component, then verify that it is part of this module.

note: the mat-tab is from angular material 2.

ChatModule

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ChatComponent } from './chat.component';
import { RoomsComponent } from './rooms/rooms.component';
import { ChatviewComponent } from './chatview/chatview.component';

@NgModule({
  declarations: [
    ChatComponent,
    RoomsComponent,
    ChatviewComponent
  ],
  imports: [
    CommonModule
  ],
  exports: [
    ChatComponent
  ]
})
export class ChatModule { }

LibraryModule

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { SharedModule } from '../../../core/modules/shared.module';
import { LibraryComponent } from './library.component';
import { ChatModule } from '../chat/chat.module';

const routes = [
  {
    path: 'library',
    component: LibraryComponent
  }
];

@NgModule({
  declarations: [
    LibraryComponent,
  ],
  imports: [
    SharedModule,
    ChatModule,
    RouterModule.forChild(routes)
  ],
  exports: [
    LibraryComponent
  ]
})
export class LibraryModule { }

ChatComponent.html

<mat-tab-group id="chat-tabs">
  <mat-tab label="Rooms">
    <fuse-rooms></fuse-rooms>
  </mat-tab>
  <mat-tab label="Contacts">
  </mat-tab>
</mat-tab-group>
John
  • 10,165
  • 5
  • 55
  • 71
Miguel Frias
  • 2,544
  • 8
  • 32
  • 53

3 Answers3

3

You Should add the material module. Like this

import {  MdtabModule } from '@angular/material';

I am not sure MdtabModule is available in angular material.

I hope this below discussions could help you.

How to import Angular Material in project?

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
3

Apparently, you have a SharedModule which exports your used MatTabsModule, you should always make sure you import the right modules for your templates.

In short:

@NgModule({
  declarations: [
    ChatComponent,
    RoomsComponent,
    ChatviewComponent
  ],
  imports: [
    SharedModule        
  ],
  exports: [
    ChatComponent
  ]
})
export class ChatModule {}

This is under the impression that you have a SharedModule at least like this:

@NgModule({
  exports: [
    MatTabsModule,
    CommonModule
  ]
})
export class SharedModule {}
Poul Kruijt
  • 69,713
  • 12
  • 145
  • 149
2

You can create custom MaterialModule where you can import modules used in your project.

MaterialModule

// Core
import {
  MatTabsModule, MatCheckboxModule, MatInputModule, MatSelectModule,
  MatButtonModule, MatDialogModule, MatTooltipModule
} from '@angular/material';
import { NgModule } from '@angular/core';

@NgModule({
  imports: [ MatTabsModule, MatCheckboxModule, MatInputModule, MatSelectModule, MatButtonModule, MatDialogModule, MatTooltipModule ],
  exports: [ MatTabsModule, MatCheckboxModule, MatInputModule, MatSelectModule, MatButtonModule, MatDialogModule, MatTooltipModule ],
})
export class MaterialModule { }

And you can import it in your SharedModule like this.

SharedModule

import { MaterialModule } from './your/path/MaterialModule';

@NgModule({
  imports: [
    ...
    MaterialModule,
    ...
  ],
  ...
)}
export class SharedModule {
...
}
mxr7350
  • 1,438
  • 3
  • 21
  • 29