|
| 1 | +import { Component, OnInit, Renderer2, ViewChild, ElementRef } from '@angular/core'; |
| 2 | +import { CategoryService } from '../../../services/category.service'; |
| 3 | +import { ActivatedRoute, Params } from '@angular/router'; |
| 4 | +import { CommunicationService } from '../shared/communication.service'; |
| 5 | +import { log } from 'util'; |
| 6 | + |
| 7 | +@Component({ |
| 8 | + selector: 'courses', |
| 9 | + templateUrl: './courses.component.html', |
| 10 | + styleUrls: ['./courses.component.scss'] |
| 11 | +}) |
| 12 | +export class CoursesComponent implements OnInit { |
| 13 | + |
| 14 | + @ViewChild('backgroundElement') backgroundElement: ElementRef; |
| 15 | + |
| 16 | + public dataIsAvailable: boolean = false; |
| 17 | + public courses: Array<any>; |
| 18 | + |
| 19 | + constructor(public categoryService: CategoryService, |
| 20 | + private activatedRoute: ActivatedRoute, |
| 21 | + public comService: CommunicationService, |
| 22 | + public renderer: Renderer2) { |
| 23 | + let localThis = this; |
| 24 | + this.comService.getColor().subscribe(color => { |
| 25 | + console.log(color); |
| 26 | + this.renderer.addClass(this.backgroundElement.nativeElement, color); |
| 27 | + }); |
| 28 | + } |
| 29 | + |
| 30 | + ngOnInit() { |
| 31 | + this.activatedRoute.params.subscribe((params: Params) => { |
| 32 | + this.categoryService.getCoursesByCategoryId(params.courseId).subscribe(response =>{ |
| 33 | + this.courses = response; |
| 34 | + if(response.name != "HttpResponseError"){ |
| 35 | + this.dataIsAvailable = true; |
| 36 | + this.courses = response; |
| 37 | + } |
| 38 | + }); |
| 39 | + }); |
| 40 | + } |
| 41 | + |
| 42 | +} |
0 commit comments