bhavesh
bhavesh

Reputation: 84

Angular 6 Material - Component is not a known element

I am trying to install Material Design in my Angular 6 app. I added Navigation schematic using the command ng generate @angular/material:nav myNav. When I compile and serve the app, I am getting error as

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

My code for app.modules.ts is as follow:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { LayoutModule } from '@angular/cdk/layout';
import { MatToolbarModule, MatButtonModule, MatSidenavModule, MatIconModule, MatListModule } from '@angular/material';
import { MyNavComponent } from './my-nav/my-nav.component';

@NgModule({
  declarations: [
    AppComponent,
    MyNavComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    LayoutModule,
    MatToolbarModule,
    MatButtonModule,
    MatSidenavModule,
    MatIconModule,
    MatListModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

My Code for app.component.html is as follows:

<my-nav></my-nav>

Please let me know where I am making mistake.

Upvotes: 3

Views: 5692

Answers (1)

pzaenger
pzaenger

Reputation: 11992

Since it's is:

@Component({
  selector: 'app-my-nav',
  templateUrl: './my-nav.component.html',
  styleUrls: ['./my-nav.component.css']
})

Your selector is app-my-nav, therefore it is <app-my-nav></app-my-nav>:

selector identifies this directive in a template and triggers instantiation of the directive.

Upvotes: 6

Related Questions