Tips for transferring information from a Sidemenu to a different page during navigation

Essentially, I have two types of users: Teachers and Students. How can I display different profile screens depending on the user type?

The Sidemenu is located in app.components.ts file.

Answer №1

When looking to navigate to specific pages,
You have options like using the router.navigate function from the component or utilizing routerLink directly in the HTML.
To organize our files, we will create separate directories for teachers and students, each with their components, CSS, and HTML files.

Step 1) The routing for these components needs to be added to the app-module.routings.ts file, which should be manually created within the app folder of your application

app-module.routings.ts

import { TeacherComponent } from './teacher/teacher.component';
import { StudentComponent } from './student/student.component';

const routes: Routes = [
  { path: '', redirectTo: '/teacher', pathMatch: 'full' },
  { path: 'teacher', component: TeacherComponent },
  { path: 'student', component: StudentComponent }
];

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

Step 2) Implementing the navigation logic

app.component.ts

export class AppComponent  {
  name = 'Changing the navigation';
  currentPage = 'teacher';
  constructor(private router: Router){}

  navigatePageTo(page) {
    this.currentPage = page;
    this.router.navigate([page]);
  }
}

Step 3) Adding the relevant links

app.component.html

<div class="sidenav">
  <a (click)="navigatePageTo('teacher')" [class.activeLink]="currentPage === 'teacher'">Teacher</a>
  <a (click)="navigatePageTo('student')" [class.activeLink]="currentPage === 'student'">Student</a>
</div>
<div class="main-content">
  <h1>{{name}}</h1>
  <hr>
</div>
<router-outlet></router-outlet>

You can view the Demo Here

I hope this meets your expectations.

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

Can a mapped union type be created in TypeScript?

Can the features of "mapped types" and "union types" be combined to generate an expression that accepts the specified interface as input: interface AwaActionTypes { CLICKLEFT: 'CL'; CLICKRIGHT: 'CR'; SCROLL: 'S'; ZOOM ...

Adding video files and subtitle files to our MongoDB database

// backend/server.ts import express, { Application, Request, Response } from 'express'; import mongoose from 'mongoose'; import cors from 'cors'; import dotenv from 'dotenv'; const multer = require('multer&apos ...

Utilizing React Native services in a similar fashion to Angular, incorporating features such as Injector

Currently experimenting with various frameworks for hybrid mobile development. Although I lean towards React Native over Angular, I am really impressed by the Injector and Provider mechanisms in Angular. The ability to have a single instance of a class cou ...

Issue: The initial parameter should be a File or Blob object

Hey there! I'm currently utilizing the compressorjs plugin for compressing images, but I'm encountering an issue when selecting images. You can find out more about the plugin here. Here is my code snippet: window.resolveLocalFileSystemURL( ...

Why is it that my side effect action is unable to identify the return action type property?

I've been working on setting up SideEffect for my authentication store, but every time I trigger the action (TrySignIn), I keep encountering this error: "AuthEffects.authSignin" dispatched an invalid action ERROR TypeError: Actions must hav ...

The @Input decorator in Angular 2/4 is designed to only transfer fundamental values and not collections or complex data

I have encountered an issue while attempting to use @Input with a list of objects, where the @Input variable ends up being undefined. What is functioning properly can be seen in home.component.html: <p> <it-easy [mycount]="countItem" (result ...

What is the best way to handle the completion of an HTTP request in Angular 8?

This is the service provided. existWayBillByRsBillNumber(billNumber: string){ return this.http.get<boolean>(this.baseUrl + 'Common/ExistWayBillByRsBillNumber/'+billNumber); } This is how the service call is made. this.commonServic ...

Replace Angular Material Component with a new custom component in Angular

In order to customize the Angular Material select component (https://material.angular.io/components/select/overview) to have an input field transformed into an icon button, I attempted to override its styling. While this approach worked well for me, I came ...

Issue with Component in Angular not functioning properly with proxy construct trap

Currently working with Angular 17, I have a straightforward decorator that wraps the target with Proxy and a basic Angular component: function proxyDecorator(target: any) { return new Proxy(target, { construct(target: any, argArray: any[], newTarget: ...

What to do when the 'image' property in Next.js next/image has an implicit 'any' type and needs fixing?

I'm a newcomer to Next.js and TypeScript and I can't seem to find any helpful resources on resolving this particular issue: import Image from 'next/image'; export default function Item({ image }) { // <-- parameter image needs a &ap ...

Merging arrays with the power of ES6 spread operator in Typescript

My goal is to merge two arrays into one using the spread object method as shown in the code snippet below: const queryVariable = { ...this.state, filters: [...Object.keys(extraFilters || {}), ...this.state.filters], } The this.state.filte ...

Validating Inputs with an Array of Values in my Angular 2 Application

I have been exploring ways to retrieve data from an array of values instead of a single value when using [(ngModel)] binding in my Angular 2 application. The current setup functions perfectly with a single value, as shown below. The data is pulled from the ...

Navigating through the typings directory in Visual Studio 2015

Is it necessary to include the typings folder as part of an asp.net application in Visual Studio 2015 when using typings? I would like to handle the typings folder similar to the bower_components folder - not checking it and not including it in my solutio ...

Communication breakdown between Auth Service and Login Component

I'm currently experimenting with Angular 4 and facing an issue with returning a boolean value from the Auth Service. Strangely, when I attempt to log the value, it shows up as undefined. My goal is to retrieve the boolean value and then utilize it in ...

The command "ng test" threw an error due to an unexpected token 'const' being encountered

Any assistance with this matter would be greatly appreciated. I am in the process of constructing an Angular 5 project using angular/cli. The majority of the project has been built without any issues regarding the build or serve commands. However, when a ...

The address :::3000 is already in use by NestJS

While attempting to deploy my NestJs server on a C-Panel hosting, I have encountered an issue. Despite properly installing all node_modules and ensuring every project file is in place, the server fails to start and continuously displays the following error ...

Acquire request data prior to exiting function in React

I am working on a NextJS application that utilizes axios for making requests to a backend API, which requires an authentication token. To handle this, I have implemented a function that retrieves the auth token and stores it in a variable at the module-lev ...

Tips for implementing debounce functionality in mui Autocomplete

How can I debounce the onInputChange function within the MyAutocomplete component? export interface AutocompleteProps<V extends FieldValues> { onInputChange: UseAutocompleteProps<UserOrEmail, true, false, false>['onInputChange']; } ...

Trouble arises when default route in Angular uses '' and '**' for 404 errors as intended

Within my app-routing.module file, I have set up child routes along with an empty route for the default login page and a '**' route for handling 404 errors. Below is the code snippet: const routes: Routes = [ { path: 'dashboard' ...

I am attempting to selectively add or remove a line-through style to a single item using Angular

I am facing an issue with my todo list app where I want to apply a line-through style to a specific item only, but currently, the line-through is being applied to all the items in the list instead of just the one I clicked on. HTML <input type="te ...