Declaring NgModules in RC5

After updating to angular 2 RC5, I was receiving warnings instructing me to relocate my components to module declarations:

The NgModule AppModule is using AcademylistComponent via "entryComponents" but it was not declared or imported! This warning will turn into an error in the final version.

In my router configuration file, I referenced these components. The original setup looked like this:

import {provideRouter,RouterConfig} from '@angular/router';
import {AcademylistComponent} from '../modules/home/component/academyList.component';
import {CourselistComponent} from '../modules/home/component/courseList.component';
import {CreateacademyComponent} from '../modules/home/component/createAcademy.component';
import {ReportsComponent} from '../modules/home/component/reports.component';
import {AuthenticatedGuard} from '../guards/authenticated.guard';

export const routes: RouterConfig = [
{
    path: '',
    redirectTo:'/home',
    terminal:true},
{
    path: 'home',
    canActivate: [AuthenticatedGuard],
    children: [

        {path: '', component: AcademylistComponent},
        {path: 'my-academies', component: AcademylistComponent},
        {path: 'my-courses', component: CourselistComponent},
        {path: 'create-academy', component: CreateacademyComponent},
        {path: 'reports', component: ReportsComponent}

    ]

}

];

export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];

When I moved the components to the ng module's declarations array and imported them there, the routes config file started showing me Cannot find name errors.

How can I properly utilize module declarations in this scenario?

Answer №1

It's important to remember that simply declaring components in your routes is not enough; you also need to declare them in the NgModule.

@NgModule({
  declarations: [
    AcademylistComponent,
    //... and any other components used in your routes
  ], 
  providers: [
    APP_ROUTER_PROVIDERS
  ]
})
export class AppModule {}

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

Strategies for splitting a component's general properties and accurately typing the outcomes

I am attempting to break down a custom type into its individual components: type CustomType<T extends React.ElementType> = React.ComponentPropsWithoutRef<T> & { aBunchOfProps: string; } The code appears as follows: const partitionProps = ...

Converting a string URL to an object type in TypeScript

Is there a way to convert a string URL into an object type in TypeScript? Here is some sample code: type KeyUrl<T> = T extends `/${infer U}` ? U : never; type TUrl<T> = { [k in KeyUrl<T>]: string }; // ---------------------------------- ...

The value of 'this.selectedNodes' does not support iteration and is causing a

I am currently utilizing v-network-graphs to generate graphs in the front end with Vue. I have set up my data like this: data(){ return{ test: test_data, nodes:{}, edges:{}, nextNodeIndex: Number, selectedNodes: ref<st ...

Types of navigation items based on conditions

I want to create an interface where a navigationItem can have optional childs for a dropdown menu. If the childs property is provided, I want to require the icon property in the navigationItem object. If no childs are given, the icon property should not be ...

Issue: NullInjectorError: R3InjectorError(AuthorModule)[ScrollbarHelper -> ScrollbarHelper -> ScrollbarHelper -> ScrollbarHelper]:

While I am going through a tutorial on the abp framework, I encountered an error with the Author route that says "ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AuthorModule)[ScrollbarHelper -> ScrollbarHelper -> ScrollbarHelp ...

Updating a child component within a Modal: A step-by-step guide

I am using a global Modal component: export const ModalProvider = ({ children }: { children: React.ReactNode }) => { const [isModalOpen, setIsModalOpen] = React.useState(false); const [config, setConfig] = React.useState<ModalConfig | nu ...

Create an array that can contain a mix of nested arrays and objects

Working on my project using Angular and TypeScript includes defining an array that can contain arrays or objects. public arrangedFooterMenu: IMenuItemType[][] | IMenuItemType[] = []; typesOfData.forEach(type => { let filteredData: IMenuItemType | ...

Can you identify a specific portion within an array?

Apologies for the poorly titled post; summarizing my query into one sentence was challenging. I'm including the current code I have, as I believe it should be easy to understand. // Constants that define columns const columns = ["a", " ...

Unable to loop through the "dataList" retrieved from a service call to the java backend within an Angular 9 application

After receiving JSON data from a Java backend service called houseguidelines, the information is sent to an Angular application via a service call. I am attempting to iterate over this returned JSON data and add it to an array I have created. Unfortunately ...

Is it acceptable to use JavaScript files in the pages directory in NEXTJS13, or is it strongly advised to only use TypeScript files in the most recent version?

In the previous iterations of nextJS, there were JavaScript files in the app directory; however, in the most recent version, TypeScript files have taken their place. Is it still possible to begin development using JavaScript? I am working on creating an a ...

Is there a way to confirm if an element's predecessor includes a specific type?

I am working on an app where I need to determine if the element I click on, or its parent, grandparent, etc., is of a specific type (e.g. button). This is important because I want to trigger a side effect only if the clicked element does not have the desir ...

I am looking to incorporate two interceptors within the Angular application - one dedicated to user authentication and another specifically for admin authentication

I am trying to differentiate between user requests and admin requests in my app. The goal is to have user requests pass through the UserAuthInterceptor, while admin requests go through the AdminAuthInterceptor. How can I separate these interceptors within ...

Angular: Excessive mat-menu items causing overflow beyond the page's boundaries

Within my mat-menu, there is a div for each mat-menu item. The number of items varies depending on the data retrieved. However, I noticed that when there are more items than can fit in the menu, it extends beyond the boundaries of the mat-menu instead of ...

Why does the bounding box in my code consistently appear at the origin instead of accurately rendering at the cursor position when the mouse is clicked?

My goal is to implement a bounding box zoom feature on a three.js render, allowing users to drag a box to specify an area for the camera to zoom in on. However, I am encountering issues with generating the box correctly. ` public dragZoom(value: boolean): ...

The attribute 'nodeQuery' is not found within the type '{}'

While working on a project with Angular and Apollo, I encountered an issue when trying to build the application using ng build. Despite functioning correctly on localhost:4200, I faced errors during the build process. The app communicates with a GraphQL se ...

Potential issue with Lodash's _.once function: the possibility of a race condition

Here's an example of code that demonstrates a scenario: const fetch = _.once(myRealFetch) const queue = new PQueue({concurrency: 1000}); queue.add(function() { const result = fetch() // Rest of the code ... }) queue.add(function() { const resul ...

Unit testing in Typescript often involves the practice of mocking

One challenge with mocking in Typescript arises when dealing with complex objects, as is the case with any strongly-typed language. Sometimes additional elements need to be mocked just to ensure code compilation, such as using AutoFixture in C#. In contras ...

Utilizing the <slot> feature in Angular 5 for increased functionality

Currently, I am working on a single page application (SPA) where Vue framework has been utilized for development purposes. Front-End: Vue Back-End: NodeJs Within my application, there are other sub-modules built in Angular 4. I am looking to replicate th ...

How to automatically scroll to the most recently added element in an *ngFor loop using Angular 2

In my web page, I have a dynamic list rendered using an ngFor loop. Users can add or remove elements from this list by clicking on a button. What I want to achieve is to automatically scroll the browser view to the latest element added when a user clicks o ...

Powerful data types for a method retrieving a value from an object

There is a function that retrieves a value by key from an object and provides suggestions of possible keys in the record when using it. This function also infers types from its arguments. function get<T extends Record<string, any>, K1 extends keyo ...