I'm trying to import a PageComponent
, which is declared inside a PageModule
. I created them by running ng g m page && cd page && ng g c page
, but failed to import PageComponent
into the app's app.component.html
.
The UI I'm creating will have a fixed sidebar and a <app-page>
which will contain the main views. Edit: I'm using ngx-admin and new to Angular. I don't understand their use of <router-outlet>
, which is the root component/placeholder for all views, so I'm trying to create my own <app-page>
. Hope this helps you to understand my intention and the UI goal.
I followed the checklist in this SO answer:
Angular 2 'component' is not a known element
Are you sure the name is correct? (also check the selector defined in the component)
- Checked, see below
Declare the component in a module? If it is in another module, export the component?
Yes. Inside the
page.module.ts
, I have:import { PageComponent } from './page.component'; import { CommonModule } from '@angular/common'; // import ...; @NgModule({ declarations: [PageComponent], imports: [ PagesRoutingModule, CommonModule ], exports: [PageComponent] // This line exports, right? }) export class PageModule { }
And the
page.component.ts
:import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-page', templateUrl: './page.component.html', styleUrls: ['./page.component.css'] }) export class PageComponent implements OnInit { constructor() { } ngOnInit() { } }
If it is in another module, import that module?
Did this in
app.module.ts
:import { PageModule } from './page/page.module'; // import ...; @NgModule({ declarations: [ AppComponent ], imports: [ // ..., PageModule // PageComponent should be available from now on ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
And the
app.component.html
, in which<app-page>
is not resolved:<nb-layout> <nb-sidebar> <nb-menu [items]="menu"></nb-menu> </nb-sidebar> <app-page></app-page> </nb-layout>
Restart the cli?
- Done
What can I do to import and use PageComponent
?
Update: After restarting the CLI & VSCode several times, the error suddenly disappeared. However, the page still doesn't show the <app-page>
component, which includes a <p>page works!</p>
.