aboutsummaryrefslogtreecommitdiff
path: root/sandbox/testAppSonja/frontend/front/src/app/main-page/main-page.component.ts
blob: cf749fc39a989fec0be0f5da52785e498d39a525 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Component, OnInit } from '@angular/core';
import { StudentService } from '../services/student.service';
import { Student } from '../Student';

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

  public students: Student[] = [];
  submitted = false;
  count: number = 0;

  constructor(private studentService: StudentService) { }

  ngOnInit(): void {
    this.studentService
      .getStudents()
      .subscribe((students : Student[]) => this.students = students);
  }

  pickStudentForDelete(id: number) {
    this.studentService.deleteStudent(id)
      .subscribe(
        data => {
          this.submitted = true;
          this.ngOnInit();
          //console.log("Data: " + data);
        }
      );
  }

}