Unable to locate the main source for loading

I am facing an issue with my app where I am unable to load a basic component. It seems like a simple problem, but I just can't seem to figure it out.

Here is the code for my component:

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import {PageStat}   from './PageStat';
import {PageStatService} from './pageStatService';
@Component({
    moduleId: module.id,
    selector: 'PageStats',
    template: '<h2>You Made it!</h2>',
    styleUrls: ['./basestyle.css']
})
export class PageStatsComponent implements OnInit{
    pagestats: PageStat[];
    selectedStat: PageStat;
    constructor(
        private router: Router,
        private pagestatservice: PageStatService){}
    getPageStatList(){
    this.pagestatservice.getPageStats().then(pagestats => this.pagestats = pagestats)

    }
    ngOnInit(): void {
    this.getPageStatList();
    }
    onSelect(selectpagestat: PageStat){
        this.selectedStat = selectpagestat;
    }
    gotoDetail(): void {
        this.router.navigate(['/detail', this.selectedStat.refid]);
    }
}

This is how my app-routing has been set up:

import { NgModule }             from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { PageStatsComponent }      from './PageStats.component';
import { PageStatDetailComponent }  from './pagestat-detail.component';

const routes: Routes = [
  { path: '', redirectTo: '/pageStats', pathMatch: 'full' },
  { path: 'pagestats/detail/:id', component: PageStatDetailComponent },
  { path: 'pageStats',     component: PageStatsComponent }
];

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

I have tried removing different parts of the component code, but nothing seems to be resolving the issue. I tried following the structure of the 'tour of heroes' example. Although many references mention a "router outlet," the tour of heroes app didn't have one and still worked fine. I'm uncertain about why or where I would need to add one in my code.

EDIT: The error message received is: Error: Cannot find primary outlet to load 'PageStatsComponent'

Answer №1

To properly render the content for the current route, make sure you have a

<router-outlet></router-outlet>

element within your HTML file.

In your main component, add the following code:

template: '<h2>Include the additional HTML content here</h2><router-outlet></router-outlet>'

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

What is the process for applying cdkDropList to the tbody when using mat-table instead of a traditional HTML table?

I have been experimenting with the mat-table component in my Angular project, following a simple example from the documentation: <table mat-table [dataSource]="dataSource" class="mat-elevation-z8"> <!--- These columns can be ...

Leveraging the power of Reactive Forms to retrieve data from a single service and dynamically generate a list

I have developed a new service that includes products with unique names and codes. I am looking to utilize this list of objects to create a comprehensive list. Can someone please assist me with this? Thank you! product.service.ts import { Injectable } fr ...

Issue with Service Workers functionality in Angular 8 has been identified

Issue http://localhost:8080/ Requests that are not handled will be directed to: http://localhost:8080 Press CTRL-C to stop the server [2019-06-21T06:37:57.110Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Geck ...

Creating a function that is accessible to the entire module

Creating a universal function in a file that is not a module: example.ts: function example() {} You can easily call this function from another file, say test.ts, without needing to import the function from example.ts: test.ts: example(); // calling univ ...

I am facing an issue with my interface - the variable designed to store boolean values

Something unusual happened with Typescript - I assigned a string value to a boolean variable, but no error was generated. I purposely triggered an error in order to observe how Typescript would react, only to find that it did not produce the expected erro ...

Node was experiencing difficulty locating a module alias that had been defined in the tsconfig file and package.json

I'm currently working on deploying a typescript project in production mode. You can find the code on Github here Executing npm run start:dev launches the server at http://localhost:3000/ Running npm run build generates the dist folder The definitio ...

Resource Not Found (404 Error) Encountered While Loading (Material Design Lite)

Embarking on my first Angular 2 project and encountering some obstacles. Utilizing WebStorm as my IDE and generated the project using Angular CLI. Facing issues when integrating Material Design Lite into the application. Have imported the necessary depe ...

Sending selected IDs from the JSON data

In my project, there is a JSON file named "workers" which contains information about all the workers. I have created a select component to display the names of the workers like this: https://i.sstatic.net/0Glyf.png Currently, I am selecting some workers ...

Experiencing the error message "delete(...).then(...).error is not a function" while attempting to remove a file from Firebase storage using AngularFire and TypeScript

I'm trying to implement the code snippet from Firebase documentation to delete a file and then upload a new image in the same directory on Firebase Storage. However, I keep encountering an error message saying "delete(...).then(...).error is not a fun ...

Show a few values as a string in Angular using Typescript

I am working with JSON data and I want to know how to display hobbies without including the word "all" in an Angular/TypeScript application. { "Name": "Mustermann1", "Vorname": "Max1", "maennlich& ...

Leverage images within the Angular library

I am currently working on creating an Angular library that includes a component with an image. I have successfully added the image as an asset in the library, but when trying to display it, the image doesn't show up. Here is the current folder structu ...

Advantages of using ConfigService instead of dotenv

What are the benefits and drawbacks of utilizing @NestJS/Config compared to using dotenv for retrieving environment variables? Although I can create a class to manage all envvars in both scenarios, is it necessary? I am aware that @NestJS/Config relies on ...

I'm working on an Angular2 project and I'm looking for a way to concatenate all my JavaScript files that were created from TypeScript in Gulp and then include them in my index

How can I concatenate all JavaScript files generated from typescript in my Angular2 project with Gulp, and then add them to my index.html file? I am using Angular2, typescript, and gulp, but currently, I am not concatenating the javascript files it genera ...

Is the @Output decorator with EventEmitter functioning properly for sibling components inside <router-outlet>?

Code Snippet from app.component.html <router-outlet> <app-header (cartRefresh)="updateCart(user_id)"></app-header> <app-breadcrumb></app-breadcrumb> </router-outlet> <app-footer></app-footer> Pull Cart Func ...

How do you implement an asynchronous validator for template-driven forms in Angular 2?

I have created a custom directive for my asynchronous validator: @Directive({ selector: '[validatorUsername]', providers: [{ provide: NG_ASYNC_VALIDATORS, useExisting: ValidatorUsernameDirective, multi: true }] }) export class ValidatorUsern ...

Creating a Jest TypeScript mock for Axios

Within a class, I have the following method: import axios from 'axios' public async getData() { const resp = await axios.get(Endpoints.DATA.URL) return resp.data } My aim is to create a Jest test that performs the following actions: jes ...

Retrieve the API output and save the information into an array

I am struggling with calling an API in my Angular application and extracting specific data from the JSON response to populate an array. Although I am able to retrieve the response, I am having trouble isolating a particular field and storing it in an array ...

The size of the content in a JWT Bearer token may be restricted by certain external fire

We are encountering an issue related to the size of JWT tokens in our system. Our current setup includes an Angular front-end and an authentication service utilizing IdentityServer4. After successful authentication, the next step involves retrieving the u ...

Angular Typescript error: Trying to assign a value to 'someProperty' property of an undefined object

Within my Article class, I have a property called Image which is structured like this: export class Article { public image:Image; public images: Image[]; } If I decide to comment out this.article.image = new Image(); in the following way: constru ...

Displaying a checkmark button highlighted when the form value is toggled to true

When working with my form, I noticed that the checkboxes, which are styled as buttons, do not remain checked when clicked. Using Angular's template-driven approach to forms, I utilize an *ngFor loop to display a selection of weekdays that can be chec ...