What is the process of showcasing a page on the dashboard using Angular?

Presently, I am working on CoreUI:

Angular CLI: 9.0.0-rc.7

I have successfully created a purchase page that displays fine individually. However, I would like to make it so that when a user clicks on the purchase page, it is displayed on the dashboard.

At the moment, my page only displays individually.

http://localhost:4200/purchase

Individual Page Purchase

To start, I created a purchase page in the view folder:

ng g c views/purchase

  • views
    • purchase
      • purchase.component.ts
      • purchase.component.html
      • purchase.component.css
      • purchase.component.spec.ts

purchase.component.html

<p>purchase works!</p>
<h1>this is an purchase pages</h1>
<h1>this is an purchase pages</h1>
<h1>this is an purchase pages</h1>
<h1>this is an purchase pages</h1>

purchase.component.ts

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

@Component({
  selector: 'app-purchase',
  templateUrl: './purchase.component.html',
  styleUrls: ['./purchase.component.css']
})
export class PurchaseComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

app.module.ts

import { PurchaseComponent } from './views/purchase/purchase.component';

@NgModule({
  imports: [
declarations: [
 PurchaseComponent

app.routing.ts

import { PurchaseComponent } from './views/purchase/purchase.component';

export const routes: Routes = [
   {
      path: '',
      redirectTo: 'dashboard',
      pathMatch: 'full',
  },
  {
      path: 'purchase',
      component: PurchaseComponent,
      data: {
          title: 'Home'
      }
  },

Although my purchase page displays fine individually, I want to incorporate it into the dashboard as well.

Dashboard Image:

enter image description here

Currently not working in dashboard.component.html

dashboard.component.html

<app-purchase>
    //empty
</app-purchase>

Answer №1

To implement the route for PurchaseComponent in your Angular application, navigate to the app.routing.ts file and include the following code within the children section:


  children: [
    {
      path: 'purchase',
      component: PurchaseComponent,
      data: {
        title: 'Purchase'
      }
    },
  ],

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

Typescript excels at gracefully handling cases where an element is not found

While working with Typescript-Protractor Jasmine, I encountered an issue where the test case (the 'it' block) is not failing when an element is not found. Instead, it shows an UnhandledPromiseRejectionWarning but still marks the script as passed. ...

Is it possible to validate a template-driven form without using the model-driven approach?

Attempting to validate a template-driven form in Angular without two-way data binding has proved to be challenging. I have successfully implemented validation using [(ngModel)], but running into an error when trying to validate the form without the MODEL p ...

Implementing chance.js in an Angular 4.x Component's ngOnInit() Method

I just started using angular 4.x and I'm trying to load change.js in the ngOnInit() function. I've attempted a few things but nothing seems to be working. Here is the code snippet: This is the code I have so far: import { Component, OnInit, In ...

Generating and setting an object property in TypeScript at runtime

In my code, I have defined an interface as follows: export interface OurHistory { ourHistory?: object; step1?:object; step2?:object; } Within the HistoryComponent class, I am doing the following: export class HistoryComponent implements OnInit, On ...

Is it possible to register multiple mini router apps using app.use() in MEAN?

Within my node/express app.js main file, I have established a mini-app router: var router = express.Router(); I pass this router to my controller functions and then export it. Finally, I register the router by using: app.use('/Link', router); ...

Customizing a side menu by assigning a function to a specific option

Hello there! I am a newcomer to TypeScript and Ionic. I am trying to implement a function that clears the cart when the "Mercado" option in the side menu is clicked, but I am struggling to retrieve the page data. The code snippet below shows my attempt to ...

Utilizing React Router with the power of useCallback

My route configuration is set up as follows: const defineRoutes = (): React.ReactElement => ( <Switch> <Redirect exact from="/" to="/estimates" /> <Route exact path="/estimates" component={CostingPa ...

Experience the ease of dragging and dropping using Dragula within Angular applications

Is it necessary to use the Dragula library for block dragging? The version 1.5.0 of the library is being used and an error is encountered: Angular: Can't bind to 'dragula' since it isn't a known property of 'div'.. How can blo ...

Exploring Angular: How to implement a listener to detect when data (such as a video) is loaded and trigger actions

I'm currently working on displaying a video in my Angular page and I'm trying to set the currentTime property of the video to start playing at a specific time. In JavaScript, you can achieve this with the following example: document.getElementBy ...

Upgrade Vue by utilizing a class object attribute

I have created a unique class with properties and I am trying to figure out how to update my vue file to reflect any changes made to the properties. I have simplified the class for now, but plan to expand it with more properties in the future. In this spe ...

The process of HTML compilation is halted due to the unexpected presence of the forbidden 'null' data type, despite the fact that null cannot actually be a valid value in

Encountering an issue with my HTML code, where the compiler stops at: Type 'CustomItem[] | null | undefined' is not compatible with type 'CustomItem[] | undefined'. Type 'null' cannot be assigned to type 'CustomItem[] ...

Getting the Value of an Object in an Array in My Angular Project

Within my Angular Application, I am receiving an array of objects from an API: "register":[ { "club": 8, "players": 100, "officials": 10 }, { "male": 7, "female": 2, "other": 1 }, { "Brazil": 5, "France": 1, "Italy": 2, "England": 2 } ] I want to specifi ...

Using location.reload with the argument of true is no longer recommended

While it's generally not recommended to reload an Angular Single Page Application, there are situations where a full reload is necessary. I've been informed by TSLint that reloading is deprecated. Is there any other solution available for this ...

Tips for customizing bootstrap cards to display on a single row with four columns

I've been working on my Angular application and I'm using a Bootstrap card to display some information. Unfortunately, I can't seem to get the design to look how I want it to, even after trying multiple approaches. The component.html code ...

Define two categories within the Attributes interface

To avoid theme-ui errors in the sx prop, I need to declare both of these statements: declare module "react" { interface Attributes { sx?: ThemeUIStyleObject; } } and declare module "react" { interface Attributes { sx?: Sx ...

Guide to building a universal model in Angular 2

How can I create a global model (class) in Angular 2? I want to be able to retrieve and set properties at any time. I attempted to achieve this as follows: export class GlobalModel { private a: number; private s: number; constructor(s: number, a ...

What sets apart angular-cli from @angular/cli in the npm ecosystem?

Two angular cli packages can be found on npm: angular-cli currently at version 1.0.0-beta.28.3 @angular/cli currently at version 1.0.0-beta.31 What sets these two packages apart, and which one is recommended for a new project? The information provided ...

What is the best way to add a number to the end of a string using Angular?

In my Angular project, I am iterating through a list of products and want to attach the index to the open or closed value. Can anyone provide assistance with this? <mat-expansion-panel *ngFor="let product of products; le ...

React application problem detected

Facing a challenge with generating a new Date object in React while using a specific date string format YYYY-MM-DD, without being affected by my machine's timezone. This issue is causing problems for a function that depends on the accurate date. Here ...

Leveraging React version 15 within Piral

The application currently in production utilizes React 15 and upgrading to the latest version, React 16, is not an immediate option. Looking ahead, I plan to incorporate piral as a whole, however, piral requires React 16 and I am unsure how to integrate R ...