Mak
Mak

Reputation: 7

Why is my angular project not serving without touching anything, just created a component that i'm trying to add to app.component.html?

Hi i'm new to angular 17, i'm following the course tour of heroes on the website. After creating the project, i create a new component heroes just like the tutorial tells me to. I add the component selector to app.component.html like this : <app-heroes></app-heroes> As i am trying to serve the project i have this error :

[ERROR] NG8001: 'app-heroes' is not a known element:

  1. If 'app-heroes' is an Angular component, then verify that it is included in the '@Component.imports' of this component.

  2. If 'app-heroes' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@Component.schemas' of this component to suppress this message. [plugin angular-compiler]

    src/app/app.component.html:0:0: 0 │ ╵ ^

Error occurs in the template of component AppComponent.

src/app/app.component.ts:9:15:
  9 │   templateUrl: './app.component.html',

Can someone help please ??

I tried to do ng serve --open and want it to serve in my browser but it's not working.

Upvotes: 0

Views: 604

Answers (1)

Mak
Mak

Reputation: 7

I found the answer. I had to import the component in app.component.ts like this :

import { HeroesComponent } from './heroes/heroes.component';

and also add it in the @Component.imports in the same file.

Upvotes: 1

Related Questions