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 { }

Answer

Your selector is ‘app-register’ but you are using ‘register’ .

Use ‘app-register’ istead of ‘register’

I hope it will solve the issue.