The Element is Unfamiliar - Application with Multiple Modules

I seem to be facing an issue with how my modules are structured, as I am unable to use shared components across different modules.

Basically, I have a Core module and a Feature module. The Core module contains components that I want to share across multiple Feature modules. The Feature module imports the Core module.

Within the FeatureModule, I have a component named PageSectionComponent that I want to display on a dashboard page. However, when trying to use the selector, I receive the error

page-section is not a known element
.

FilePath

src
   - components
      - site-layout.component.html
      - site-layout.component.ts
   - modules
      - core
         - core-routing.module.ts
         - core.module.ts
      - feature
         - pages
            - dashboard-page.component.html
            - dashboard-page.component.ts
         - components
            - page-section.component.html
            - page-section.component.ts
         - feature-routing.module.ts
         - feature.module.ts

feature.module.ts

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

import { FeatureRoutingModule } from './feature-routing.module';
import { CoreModule } from '../core/core.module';

@NgModule({
  imports: [
    CoreModule,
    FeatureRoutingModule
  ]
})
export class FeatureModule {}

core.module.ts - imports both the SiteLayout and the PageSection.

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { SiteLayoutComponent } from 'app/components';
import { CoreRoutingModule } from './core-routing.module';

import { PageSectionComponent } from '@feature/components';

@NgModule({
  declarations: [
    PageSectionComponent,
    SiteLayoutComponent
  ],
  imports: [
    CommonModule,
    CoreRoutingModule,
  ],
  exports: [
    PageSectionComponent,
    SiteLayoutComponent
  ]
})
export class CoreModule {}

The problem seems to lie within my routing configuration. I am using the SiteLayoutComponent to wrap pages from both the Core and Feature modules. Thus, my FeatureRoutingComponent looks like this, where all paths include the SiteLayoutComponent, followed by the specific Dashboard or other component based on the path.

feature-routing.component.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SiteLayoutComponent } from '@components/layouts/site-layout.component';
import { DashboardPageComponent } from '@feature/pages';

const routes: Routes = [
  {
    path: '',
    component: SiteLayoutComponent,
    children: [
      { path: '', redirectTo: 'dashboard', pathMatch: 'full' }, 
      { path: 'dashboard',  component: DashboardPageComponent }
    ]
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class FeatureRoutingModule { }

Currently, the SiteLayoutComponent only contains the router-outlet.

site-layout.component.html

<router-outlet></router-outlet>

My trouble starts when attempting to place a 'PageSectionComponent' in the DashboardPageComponent.

dashboard-page.component.html

<page-section></page-section>

This results in the error stating that page-section is not a recognized element.

After researching multi-module applications, it seems that adding the PageSectionComponent to the CoreModule's imports + exports and then importing the CoreModule within the FeatureModule should work, but it doesn't.

My current hypothesis is that because the Site-Layout is a shareable component referenced directly in feature-routing.module.ts AND core.module.ts, it may be causing the imported PageSectionComponent to lose scope somehow.

Answer №1

Hey there, I see that you're having trouble with declaring your DashboardPageComponent in the code snippet provided. It seems like defining this component is necessary before proceeding further.

To resolve this issue, consider incorporating a declaration similar to the following:

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

import { FeatureRoutingModule } from './feature-routing.module';
import { DashboardPageComponent } from './feature.module';
import { CoreModule } from '../core/core.module';

@NgModule({
  declarations:[
     DashboardPageComponent 
  ],
  imports: [
    CoreModule,
    FeatureRoutingModule
  ],
  exports: [
    DashboardPageComponent
   ]
})
export class FeatureModule {}

Remember to ensure all components are imported properly within your project structure.

Moreover, revisiting the modularity approach might be beneficial as the current setup appears to be somewhat confusing.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The TypeScript rule in the project-specific .eslintrc.js file is not being applied as expected

Currently, I am following a tutorial on Ionic/Vue 3 which can be found here. However, when I try to serve the project, I encounter the following error: https://i.stack.imgur.com/k4juO.png It appears that my project-level .eslintrc.js file is not being ap ...

You can't access the values from one subscribe in Angular 2 within another subscribe (observable) block

Is there a way to properly handle the values from the subscribe method? I am facing an issue where I want to use this.internships in another subscribe method but it keeps returning undefined. Your assistance is greatly appreciated! Code: ngOnInit(): voi ...

What is the reason that the command `npx create-react-app my-app --typescript` is not providing me with the expected TypeScript files?

I used the command npx create-react-app my-app --typescript to create my React project, but it seems like I still ended up with the default JavaScript boilerplate files. I was expecting to see files with a .tsx or .ts extension and use import * from as R ...

The functionality of Angular Custom Validation using Directive is experiencing issues within the ng-change event

I have created a custom validator using directives to validate email addresses. The validation is triggered by a method called on ng-change, but the validation only displays on the second change of the input. <textarea id="txtEmail" name=&qu ...

Issue: The --outFile flag only supports 'amd' and 'system' modules

Encountering an issue while trying to compile an Angular project in Visual Studio Code using ng build and then serving it with ng serve Unfortunately, faced the following error message in both cases: The error 'Only 'amd' and 'syste ...

Is it possible that Angular2 is unable to properly establish the default value when it is selected?

I've been attempting to establish a default value for my selection by using [selected]= "selected_choice == 'one'" similar to this method but unfortunately, it didn't yield the desired result. Upon hearing that [selected] is no long ...

The Generic Function's Return Type in Typescript

The latest addition of ReturnType in TypeScript 2.8 is a highly valuable feature that enables you to capture the return type of a specific function. function foo(e: number): number { return e; } type fooReturn = ReturnType<typeof foo>; // numbe ...

Searching for an Angular 7 alternative to Vue.js's "nextTick" function

In my Angular 7 project, I'm facing a situation where I need to automatically scroll to a specific section on the page after it has been fully rendered. The section is initially hidden using ngif and should only be scrolled to once it is visible in th ...

Angular 10: Display a notification when all checkboxes have been ticked

I am currently working on a project that involves Angular 10. The initial requirement was as follows: Users are presented with a list from which they need to choose one option using radio buttons. For example: the user selects covid19 from the given lis ...

Arrange two input fields side by side if the quantity of input fields is unspecified

I am currently in the process of developing a project using Angular. I have implemented an *ngFor loop to dynamically add input fields based on the data retrieved from the backend. Is there a way I can ensure that two input fields are displayed on the same ...

What are effective strategies for troubleshooting Dependency Injection problems in nest.js?

Can someone explain the process of importing a third-party library into NestJS using Dependency Injection? Let's say we have a class called AuthService: export class AuthService { constructor( @Inject(constants.JWT) private jsonWebToken: any, ...

Tips for verifying the connections between an Angular application and Azure Function (negotiate) when integrating with Azure SignalR Service

I'm working on an angular application that is authenticated with Azure AD, connecting to an Azure Function (negotiate) which then communicates with Azure SignalR service using specific keys. I am looking for guidance on how to authenticate requests ma ...

Replace the default Material UI 5.0 typography theme with custom fonts on a global scale

My current challenge involves incorporating two personal fonts into the Material UI 5.0. My goal is to apply these fonts globally by overriding the theme settings. However, I have encountered issues with loading the fonts properly and modifying the typogra ...

Issue with file upload controller in .net core 2.2 and Angular 7: IFormFile always returns null

Despite thorough research and checking other answers, my controller is not receiving any data. Correct API URIs are used and the request does reach the appropriate controller. Unique Angular Snippet: In the component.html file - input field setup <d ...

Error: Unable to connect to 'ngbTypeahead' as it is not recognized as a valid attribute of 'input' in the template

Having trouble with ngbTypeahead. The console is displaying the following error message: Error: Template parse errors: Can't bind to 'ngbTypeahead' since it isn't a known property of 'input'. (" <inpu ...

Tips for emphasizing active tabs in Angular 6

**I have everything displaying perfectly, but I am wondering how to highlight the active tab without using any third-party components. Any assistance would be greatly appreciated. Thank you.** <ul class="tabs"> <li [ngClass]=" {'active-tab ...

Angular2-starter configuration setup with environment-based variables (such as .env or .conf) for testing and production settings

Frameworks like PHP Laravel often include files for local configuration, separate from dev, test, and production environments. How can a configuration file be provided for an angular-starter project that contains all local environment variable values (su ...

Tips for selecting the best className type for material-ui components

Currently, I am integrating material-ui into a react app that is built using typescript. Within the material-ui framework, there is a feature called withStyles which allows styles to be injected into a component through its className. However, I am facing ...

checkbox causing the button to appear empty

Due to the inability of a ngIf and ngFor to coexist, I added an ng-container to facilitate the loop. However, after making this change, nothing seems to be working as expected without any clear reason. Below is the code snippet that is causing trouble: Vi ...

Guidance on transferring information from a parent component to an Angular Material table child component

Currently, I am implementing an angular material table with sorting functionality. You can view the example here: Table Sorting Example I intend to transform this into a reusable component so that in the parent component, all I have to do is pass the colu ...