Hi I have a table in a page where it shows the list of all students And when we click on view button in the table, it takes to other page where it shows the details of specific student.
The list of students is component 1 and student details is component 2.
How do I send data when they click on 'View/Edit' button to other component ?
1st -> student-list.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { Router, ActivatedRoute, RouterModule } from '@angular/router';
@Component({
selector: 'app-student-list',
templateUrl: './student-list.component.html',
styleUrls: ['./student-list.component.scss']
})
export class StudentsListComponent implements OnInit {
userData: any;
selectedUser: any;
constructor(public router: Router, public route: ActivatedRoute) { }
ngOnInit() {
this.getStudentList();
}
getStudentList() {
this.http.get<Student>('*url*')
.subscribe(data => {
this.student = data;
});
}
}
2nd -> student.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { Router, ActivatedRoute, RouterModule } from '@angular/router';
@Component({
selector: 'app-student-selected',
templateUrl: './student.component.html',
styleUrls: ['./student.component.scss']
})
export class SelectedStudentComponent implements OnInit {
constructor(public router: Router, public route: ActivatedRoute) { }
ngOnInit() {
}
}