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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import { Component, OnInit } from '@angular/core';
import { NgForm } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { StudentService } from '../services/student.service';
import { Student } from '../Student';
@Component({
selector: 'app-edit-page',
templateUrl: './edit-page.component.html',
styleUrls: ['./edit-page.component.css']
})
export class EditPageComponent implements OnInit {
submitted = false;
id: number = -1;
student = new Student();
constructor(private studentService: StudentService, private route: ActivatedRoute, private router: Router) { }
ngOnInit(): void {
this.route.paramMap.subscribe(
params => this.id = parseInt(params.get('id')!)
);
this.loadOneStudent();
}
loadOneStudent() {
this.studentService.getOneStudent(this.id)
.subscribe(
data => this.student = data
)
}
handleSubmit(f: NgForm) { //f.value su name-ovi pokupljeni iz forme pa njihove vrednosti
let editedStudent : Student = {
id: f.value.id,
firstName: f.value.firstname, //znaci ovo je name iz forme
lastName: f.value.lastname,
regNum: f.value.regNum,
address: f.value.address,
phoneNum: f.value.phone,
gpa: f.value.gpa
}
this.studentService.updateStudent(this.id, editedStudent)
.subscribe(
data => {
this.submitted = true;
//console.log("Form:", f.value);
this.router.navigate(['']);
}
)
}
}
|