Lazy loading feature modules in Angular 2 provides the ability to load modules on demand without rendering

It seems like I might be overlooking something simple here, but I just can't seem to find it.

Based on my observations, my feature module is lazy loading successfully (as seen in dev tools where files are only loaded when the required link is selected). I have added breakpoints in the code and confirmed that it is reaching the template inside timesheet.component. However, the template is not rendering, resulting in a blank page (except for the navbar component that does render).

The relevant files being loaded are:

1:

// timesheet.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { timesheetRoutes } from './timesheet.routes'
import { TimesheetComponent } from './timesheet.component'

@NgModule({
imports: [ CommonModule, RouterModule.forChild(timesheetRoutes) ],
declarations: [ TimesheetComponent ],
providers: [ ]
})
export class TimesheetModule

2:

// timesheet.routes.ts
import { Routes, RouterModule } from '@angular/router'
import { TimesheetComponent } from './timesheet.component'

export const timesheetRoutes: Routes = [
{ path: 'timesheet', component: TimesheetComponent }
]

3:

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

@Component({
template: `<h1>Mobile Timesheet</h1>`
})

export class TimesheetComponent  {
}

My routes are defined as follows:

// routes.ts

import { CaseListComponent } from './cases/case-list.component';
import { CaseDetailComponent } from './cases/case-details/case-details.component';

import { Routes } from '@angular/router'

import { CaseListResolverService } from './cases/case-list-resolver.service';

export const appRoutes:Routes = 
[
{ path: 'cases', component: CaseListComponent, resolve:
{cases:CaseListResolverService} },
{ path: 'cases/:irn', component: CaseDetailComponent },
{ path: '', redirectTo: '/cases', pathMatch: 'full' },
{ path: 'timesheet', loadChildren: 
'app/timesheet/timesheet.module#TimesheetModule' }
]

The App component is bootstrapped and makes the following call:

<nav-bar></nav-bar>
<router-outlet></router-outlet>

navbar contains a routerLink as follows:

<a [routerLink]="['timesheet']">Time Sheet</a>

Answer №1

To set the route for the empty path in the timesheet.routes.ts file is essential.

In the current setup, the TimesheetComponent will only be triggered when navigating to the timesheet/timesheet route.

Remember that any routes specified within a module are considered children of the routes defined in the appRoutes section of the routes.ts file.

You should update it as follows:

export const timesheetRoutes: Routes = [
  { path: '', component: TimesheetComponent }
]

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

Mobile application built on Ionic 2 featuring Bluetooth Low Energy (BLE) capabilities

I am in the process of developing an Ionic 2 application that displays a list of all accessible Bluetooth devices and establishes connections with them effortlessly. I began by setting up a new Ionic v2 project and adding the BLE plugin to it. Your help w ...

What is the process of integrating SCSS into an Angular2 Seed Project?

Is there a recommended method for incorporating SCSS into an Angular2 Seed Project? Are there any informative tutorials or reference sites available? I attempted to implement SCSS following instructions from this link https://github.com/AngularClass/angu ...

What is the most effective method to clean an object in JavaScript while maintaining security?

To circumvent the JavaScript delete operator (source: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Operators/delete), I have opted to utilize object destructuring to eliminate private properties: //sample helper-function in ts const sani ...

Guide to effectively utilizing a lone boolean variable within Angular to dynamically manipulate various fields

Within my form, I have 10 text areas and 10 CKE editors. Initially, only the text areas are displayed upon loading. Each text editor has a toggle button located at the top. When this toggle function is called, the respective editor should switch to a CKE ...

The return type in Typescript for dynamically generated return values

If I have a function in Typescript 2.0 like this: doSomething(): any { const apple: Apple = ... const pears: Pear[] = ... return { apple: apple, pears: pears } } I am aware that the function will always produce an object ...

Blending Angular5 and AngularJS in Polymer

We are considering launching two new projects - one using Angular 5 and the other utilizing Polymer. The second project is intended to serve as a component library for reuse in not only the Angular 5 project but also in other AngularJS projects. After res ...

Is there a way to display only the first x characters of an HTML code while disregarding any tags present within

When I work with a text editor, it generates HTML code that I save in the database. On another page, I need to display only the first 100 characters of the text without counting the HTML tags. For instance, let's say this is the HTML code saved in th ...

Encountering an Angular schematics issue while utilizing an external schematic ng-new, the specified version is

Attempting to develop a schematic that utilizes the angular ng-new as the initial call and another schematic to add a prettier file to the new project. Upon executing the command, an error is encountered: Data path "" must have required property 've ...

Implementing an All-Routes-Except-One CanActivate guard in Angular2

In order to group routes within a module, I am aware that it can be done like this: canActivate: [AuthGuard], children: [ { path: '', children: [ { path: 'crises', component: ManageCrisesComponent }, ...

Map the API response to the color of the column to show which specific column was modified

I need to dynamically change the color of a column in a table based on data updates from an API. Unfortunately, I can't share my code, but I would appreciate any examples or suggestions on how to achieve this. APIs are not my strong suit, so any guid ...

Angular2 is now caching components, which is helping to prevent view caching issues

In Angular 1, includes were automatically cached in the browser. It was common practice to add a version as a query string in data includes as a workaround. What methods can be used in Angular2 to prevent or control caching? For example, updating or rele ...

SASS property value validation error

I am having trouble using a Font in Storybook as I keep getting the error "invalid property value" in Chrome. I am new to sass and storybook. Error Screenshot: https://ibb.co/HqFLJ5H Main Sass File (excerpt): @import './src/assets/sass/color.sass&a ...

Having trouble with unsubscribing from an initialized observable in Angular 4 ngOnDestroy method

I encountered an error message stating: Uncaught Type Error: Cannot read property 'unsubscribe' of undefined. Despite trying various solutions found online, I have been unable to resolve the issue. I even checked the object in the console during ...

By leveraging core-js and Typescript with ES5 as the target, it is possible to utilize ES6 features

Currently, I am working on a TypeScript project that is compiled with the setting "target": "es5". In order to use core-js's Set, I have both core-js and @types/core-js installed in my project. The issue arises because the core-js d.ts file contains g ...

Angular2 had a delay in processing the 'mouse wheel' input event for x milliseconds because the main thread was occupied

Currently, I am working with Angular2 (r.2.0.0) along with typescript (v.1.8.10). I have encountered an issue where Chrome does not respond while scrolling and displays a warning message stating: "Handling of 'mouse wheel' input event was delayed ...

Encountering an issue with Angular Material's MatTable when trying to set the datasource data to an interface

My angular material mat-table previously used a data type interface, which looked like this: dataSource : MatTableDataSource<IAddress>; dataSource.data = this.testData; interface IAddress { name: string; address: string: city: string; state: ...

The POST requests on Next JS Mock API endpoints include parameters passed in the req.body

I am currently running Next JS API tests using jest with a custom testClient. The code for the testClient is as follows: import { createServer } from 'http'; import type { NextApiHandler } from 'next'; import type { __ApiPreviewProps } ...

elements communicate using the <router-outlet>

I am currently facing a situation where I have a root component containing a boolean value that changes dynamically. I need to subscribe to this changing boolean from a component within my <router-outlet>. I believe the best approach is to use a shar ...

Encountered a problem during the installation of Angular 4

Recently delving into angular, my journey began with the installation of node js on my machine. Following this link, I attempted to install angular, only to be met with the following error: gyp verb check python, inspecting if Python executable "python" i ...

Determine the type of connection using knex

I am currently developing an application that needs to support both MySQL and Postgres databases simultaneously through Knex. However, I have encountered a limitation with the query builder for certain features, which requires me to write specific queries ...