Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to display components using their selector in Angular 17

Right now I’m playing around with Angular 17 (Angular CLI: 17.0.0).

The directory is structured as follows:

/src
    /app
        /x
            x.component.css
            x.component.html
            x.component.spec.ts
            x.component.ts
        app.component.css
        app.component.html
        app.component.spec.ts
        app.component.ts
        app.config.ts
        app.routes.ts
    /assets
    favicon.ico
    index.html
    main.ts
    styles.css

I want to include the content of my component x by adding <app-x></app-x> to app.component.html and importing x in app.component.ts. However the content of that component is not displayed in the app.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What am I doing wrong?

>Solution :

You need to import the class of your component defined in x.component.ts

export class XComponent {

}

Then on your app.component.ts you add in the imports array

@Component({
  ...
  imports: [CommonModule, RouterOutlet, XComponent],
  ...
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading