0

Problem:

To display (custom) Navigation component (titled topnav) in app.component.html

app.module.ts

   import { TopnavComponent } from './topnav/topnav.component';

   @NgModule({
         declarations: [
            AppComponent,
            TopnavComponent,
         ]
    })

*edited to show AppComponent inside of declarations

app.component.html

 <topnav></topnav>

SOLUTION

<app-topnav></app-topnav>

topnav.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-topnav',
  templateUrl: './topnav.component.html',
  styleUrls: ['./topnav.component.css']
})
export class TopnavComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

*edited to show topnav.component.ts

Not sure what I am missing here. I attempted to try different directives, importing and exporting in different ways. I know this is a basic idea behind Angular but having trouble and has been documented with Angular 2 but their solutions were not resolving in Angular 8.

Still getting this error:

1. If 'topnav' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
  <div class="container">

   [ERROR ->]<topnav></topnav>

  </div>
"): ng:///AppModule/AppComponent.html@4:3

When adding to imports:[] in app.module.ts, from my understanding only takes modules based on the error I was getting.

6
  • where is the AppComponent inside your declarations array Commented Sep 30, 2019 at 16:53
  • I omitted when copying over the code - it is in there. Edit to show true code. Commented Sep 30, 2019 at 16:56
  • Can you show us the code for topnav component? Commented Sep 30, 2019 at 17:00
  • added topnav component. the HTML file within the component is for all purposes just a string that says 'test' right now. I removed all other formatting to just get the component to show. Commented Sep 30, 2019 at 17:02
  • 2
    You are using the wrong selector. It should be <app-topnav></app-topnav> in app.component.html. Commented Sep 30, 2019 at 17:04

1 Answer 1

1

You are using the wrong selector. Replace app.component.html with this:

 <app-topnav></app-topnav>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.