source: Sources/frontend/src/app/question/question.component.ts@ 8423429

Last change on this file since 8423429 was 8423429, checked in by AngelNasev <angel.nasev@…>, 17 months ago

Add backend and frontend projects

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[8423429]1import {Component} from '@angular/core';
2import {QuestionInterface} from "../QuestionInterface";
3import {QuestionService} from "../question.service";
4import {ActivatedRoute, Router} from "@angular/router";
5import {CourseService} from "../course.service";
6import {CourseInterface} from "../courseInterface";
7import {LoginService} from "../login.service";
8import {ActiveUserInterface} from "../ActiveUserInterface";
9
10@Component({
11 selector: 'app-question',
12 templateUrl: './question.component.html',
13 styleUrls: ['./question.component.css']
14})
15export 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}
Note: See TracBrowser for help on using the repository browser.