-
Notifications
You must be signed in to change notification settings - Fork 395
/
Copy pathcourse-dialog.component.ts
59 lines (44 loc) · 1.54 KB
/
course-dialog.component.ts
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
57
58
59
import {AfterViewInit, Component, Inject} from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog";
import {Course} from "../model/course";
import {FormBuilder, Validators, FormGroup} from "@angular/forms";
import * as moment from 'moment';
import { CoursesService } from '../services/courses.service';
import { LoadingService } from '../services/loading.service';
@Component({
selector: 'course-dialog',
templateUrl: './course-dialog.component.html',
styleUrls: ['./course-dialog.component.css']
})
export class CourseDialogComponent implements AfterViewInit {
form: FormGroup;
course:Course;
constructor(
private fb: FormBuilder,
private dialogRef: MatDialogRef<CourseDialogComponent>,
private courseService: CoursesService,
private loadingService: LoadingService,
@Inject(MAT_DIALOG_DATA) course:Course) {
this.course = course;
this.form = fb.group({
description: [course.description, Validators.required],
category: [course.category, Validators.required],
releasedAt: [moment(), Validators.required],
longDescription: [course.longDescription,Validators.required]
});
}
ngAfterViewInit() {
}
save() {
const changes = this.form.value;
this.courseService.saveCourse(this.course.id, changes)
.subscribe(
(val) => {
this.dialogRef.close(val);
}
);
}
close() {
this.dialogRef.close();
}
}