1 | import {Component} from '@angular/core';
|
---|
2 | import {QuestionInterface} from "../QuestionInterface";
|
---|
3 | import {QuestionService} from "../question.service";
|
---|
4 | import {ActivatedRoute, Router} from "@angular/router";
|
---|
5 | import {CourseService} from "../course.service";
|
---|
6 | import {CourseInterface} from "../courseInterface";
|
---|
7 | import {LoginService} from "../login.service";
|
---|
8 | import {ActiveUserInterface} from "../ActiveUserInterface";
|
---|
9 |
|
---|
10 | @Component({
|
---|
11 | selector: 'app-question',
|
---|
12 | templateUrl: './question.component.html',
|
---|
13 | styleUrls: ['./question.component.css']
|
---|
14 | })
|
---|
15 | export class QuestionComponent {
|
---|
16 | questions: QuestionInterface[] = []
|
---|
17 | course: CourseInterface | undefined;
|
---|
18 | activeUser: ActiveUserInterface | undefined;
|
---|
19 |
|
---|
20 | constructor(private service: QuestionService,
|
---|
21 | private route: ActivatedRoute,
|
---|
22 | private courseService: CourseService,
|
---|
23 | private loginService: LoginService,
|
---|
24 | private router: Router) {
|
---|
25 | }
|
---|
26 |
|
---|
27 | ngOnInit(): void {
|
---|
28 | const id = Number(this.route.snapshot.paramMap.get('id'));
|
---|
29 | this.activeUser = this.loginService.activeUser;
|
---|
30 | if (!this.activeUser) {
|
---|
31 | this.router.navigate(['/'])
|
---|
32 | }
|
---|
33 | this.findCourseById(id);
|
---|
34 | this.getAllQuestionsForCourse(id);
|
---|
35 | }
|
---|
36 |
|
---|
37 | findCourseById(id: number) {
|
---|
38 | this.courseService.findCourseById(id).subscribe(resp => {
|
---|
39 | this.course = resp
|
---|
40 | })
|
---|
41 | }
|
---|
42 |
|
---|
43 | getAllQuestionsForCourse(id: number) {
|
---|
44 | this.service.getAllQuestionsForCourse(id).subscribe(questions => this.questions = questions);
|
---|
45 | }
|
---|
46 |
|
---|
47 | }
|
---|