Angular-AppComponent error. How solve it?

Discussão em 'Angular' iniciado por Leichtos, Dezembro 29, 2024.

  1. Leichtos

    Leichtos Guest

    I have a problem with my Angular project. In my app.module.ts the code is below:

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { AppRoutingModule } from './app-routing.module';
    import { AppComponent } from './app.component';
    import { BmiModule } from './bmi/bmi.module';

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


    My app.component.ts is below:

    import { Component } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { RouterOutlet } from '@angular/router';


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

    export class AppComponent {
    title = 'WP4_HF_004';
    }


    My app.component.html:

    <h1>BMI kalkulátor</h1>
    <p>Ez egy BMI kalkulátor. A lenti 4 gomb segítségével lehet módosítani a súly- és magasságparamétereket.
    <app-bmi-calculator></app-bmi-calculator>
    </p>


    I got an error in app.module.ts:


    Component AppComponent is standalone, and cannot be declared in an NgModule. Did you mean to import it instead?
    ​

    If I didn't import my AppComponent in app.module.ts I get an error in app.component.html:


    'app-bmi-calculator' is not a known element:

    1. If 'app-bmi-calculator' is an Angular component, then verify that it is included in the '@Component.imports' of this component.
    2. If 'app-bmi-calculator' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@Component.schemas' of this component to suppress this message.ngtsc(-998001) app.component.ts(4, 5):
    ​

    Error occurs in the template of component AppComponent.

    I searched the problem on the internet but I didn't find the solve.

    Continue reading...

Compartilhe esta Página