Adriel Silvestre
Adriel Silvestre

Reputation: 163

Angular: error NG8001: 'component' is not a known element

I'm trying to use a component ('register') inside the app.component and it throws me this error:

Error: src/app/app.component.html:88:1 - error NG8001: 'register' is not a known element:

  1. If 'register' 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.

88

My app.component.html:

...
<register></register>
...

My register.component.ts:

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

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

  public title:string;

  constructor() {
    this.title = 'Registrar';
  }

  ngOnInit(): void {
    console.log('Componente de registro cargado');
  }

}

My app.component.ts:

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'red soc';
}

My app.module.ts

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

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { RegisterComponent } from './register/register.component';

@NgModule({
  declarations: [
    AppComponent,
    RegisterComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Upvotes: 10

Views: 26949

Answers (2)

ani0904071
ani0904071

Reputation: 368

Apart from the answer mentioned by @Arijit Bag, add(import) the ComponentName that you want to include into app.component.ts (angular 17.3.8), For ex: RegisterComponent

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [...., RegisterComponent],
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss'
})

Upvotes: 1

Arijit Bag
Arijit Bag

Reputation: 170

Your selector is 'app-register' but you are using 'register' .

Use 'app-register' istead of 'register'

I hope it will solve the issue.

Upvotes: 7

Related Questions