-
Notifications
You must be signed in to change notification settings - Fork 0
/
course.component.ts
83 lines (70 loc) · 1.7 KB
/
course.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import {
Component,
EventEmitter,
Input,
OnInit,
Output,
AfterViewInit,
OnDestroy,
ElementRef,
DoCheck
} from "@angular/core";
import { Course } from "src/app/model/course";
const DEBUG = false;
@Component({
selector: "app-course",
templateUrl: "./course.component.html",
styleUrls: ["./course.component.css"]
})
export class CourseComponent
implements OnInit, AfterViewInit, OnDestroy, DoCheck {
@Input() course: Course;
@Input() editable = false;
@Output() courseSelected = new EventEmitter<Course>();
@Output() courseEdited = new EventEmitter<Course>();
@Output() courseRemoved = new EventEmitter<Course>();
//Ready in terms of Typescript
constructor(private el: ElementRef<HTMLElement>) {
this.logIt("constructor");
}
//Ready in terms of Angular framework
ngOnInit() {
this.logIt("ngOnInit");
// console.log("ngOnInit");
if (DEBUG) {
setInterval(() => {
this.course = Object.assign({}, this.course);
this.course.price = Math.round(Math.random() * 100);
}, 2000);
}
}
ngDoCheck(): void {
this.logIt("ngDoCheck");
}
ngAfterViewInit(): void {
this.logIt("ngAfterViewInit");
}
ngOnDestroy(): void {
this.logIt("ngOnDestroy");
}
onClick(event: Event) {
event.preventDefault();
this.courseSelected.emit(this.course);
}
onEdit() {
this.courseEdited.emit(this.course);
}
onRemove() {
this.courseRemoved.emit(this.course);
}
logIt(checkpoint: string) {
if (DEBUG) {
console.log(
"args at " + checkpoint + " - " + JSON.stringify(this.course)
);
console.log(
"view at " + checkpoint + " - " + this.el.nativeElement.textContent
);
}
}
}