I am working on a project that involves two components: a login component and a home component. I need to pass user data from the login component to the home component without using local storage. Is there a way to achieve this in Angular 8? Below is the code snippet for reference.
LoginComponent.ts
import { Component, OnInit } from '@angular/core';
import { CommonserviceService } from './../utilities/services/commonservice.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
users:any;
constructor(private commonserviceService: CommonserviceService,private router: Router) { }
ngOnInit() {
this.users = [{"user1":"abc"},{"user2":"abcd"},{"user3":"abce"},{"user4":"abt"}];
}
storeData(){
this.router.navigate(['/home']);
}
}
LoginComponent.html
<button (click)="storeData()">Go To Home Page</button>
HomeComponent.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
getListData: any;
constructor() { }
ngOnInit() {
}
}