source: Sources/frontend/src/app/subject/subject.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.3 KB
Line 
1import {Component, ViewChild} from '@angular/core';
2import {SubjectInterface} from "../subjectInterface";
3import {SubjectService} from "../subject.service";
4import {ActiveUserInterface} from "../ActiveUserInterface";
5import {LoginService} from "../login.service";
6import {AllCoursesComponent} from "../all-courses/all-courses.component";
7import {Router} from "@angular/router";
8
9@Component({
10 selector: 'app-subject',
11 templateUrl: './subject.component.html',
12 styleUrls: ['./subject.component.css']
13})
14export class SubjectComponent {
15
16 subjects: SubjectInterface[] = [];
17 subjectId: number | undefined;
18 activeUser: ActiveUserInterface | undefined;
19 @ViewChild(AllCoursesComponent) child!: AllCoursesComponent;
20
21 constructor(private service: SubjectService,
22 private loginService: LoginService,
23 private router: Router) {
24 }
25
26 ngOnInit(): void {
27 this.activeUser = this.loginService.activeUser!!;
28 if (!this.activeUser) {
29 this.router.navigate(['/'])
30 }
31 this.service.getAllSubjects()
32 .subscribe(subjects => this.subjects = subjects);
33 }
34
35 onChange({event, id}: { event: any, id: any }) {
36 if (event.target.checked) {
37 // @ts-ignore
38 this.subjectId = id
39 this.child.loadCourses(id.id);
40 } else {
41 // @ts-ignore
42 this.subjectId = null;
43 }
44 }
45
46}
Note: See TracBrowser for help on using the repository browser.