1- import { Component , Renderer2 , ViewChild , ElementRef , AfterViewInit , OnInit } from '@angular/core' ;
1+ import { Component , Renderer2 , ViewChild , ElementRef , OnInit } from '@angular/core' ;
22import { CategoryService } from '../../../services/category.service' ;
33import { ActivatedRoute , Params } from '@angular/router' ;
44import { CommunicationService } from '../shared/communication.service' ;
@@ -16,25 +16,24 @@ export class CoursesComponent implements OnInit {
1616 @ViewChild ( 'backgroundElement' ) backgroundElement : ElementRef ;
1717
1818 public dataIsAvailable : boolean = false ;
19- public courses : Array < any > ;
19+ public courses : Array < any > = [ ] ;
2020 public headerText : string = "" ;
2121 public category : string = "" ;
2222
2323 constructor (
24- public categoryService : CategoryService ,
25- public userService : UserService ,
26- private activatedRoute : ActivatedRoute ,
27- public comService : CommunicationService ,
28- public coursesService : CoursesService ,
29- public renderer : Renderer2 ) { }
30-
31- ngOnInit ( ) {
32- this . comService . getInfo ( ) . subscribe ( response => {
33- this . category = response . category ;
34- this . renderer . addClass ( this . backgroundElement . nativeElement , response . color ) ;
35- } ) ;
24+ public coursesService : CoursesService ,
25+ public categoryService : CategoryService ,
26+ public userService : UserService ,
27+ private activatedRoute : ActivatedRoute ,
28+ public comService : CommunicationService ,
29+ public renderer : Renderer2 ) {
30+ this . comService . getInfo ( ) . subscribe ( color => {
31+ //this.renderer.addClass(this.backgroundElement.nativeElement, color);
32+ } ) ;
33+ }
3634
37- this . activatedRoute . params . subscribe ( ( params : Params ) => {
35+ ngOnInit ( ) {
36+ this . activatedRoute . params . subscribe ( ( params : Params ) => {
3837 if ( params . id == "me" ) {
3938 this . requestCoursesByUser ( ) ;
4039 }
@@ -46,24 +45,25 @@ export class CoursesComponent implements OnInit {
4645
4746 requestCoursesByUser ( ) :void {
4847 this . headerText = "Meine" ;
49- this . userService . getCoursesByUser ( ) . subscribe ( response => {
50- response . forEach ( element => {
51- this . courses = [ ] ;
52- this . coursesService . getCoursesByCourseId ( element . ANM_KURS_ID ) . subscribe ( response => {
53- response . ANM_DATUM = element . ANM_DATUM ;
54- this . courses . push ( response ) ;
48+ this . courses = [ ] ;
49+ this . userService . getCoursesByUser ( ) . subscribe ( responseUser => {
50+ responseUser . forEach ( element => {
51+ this . coursesService . getCoursesByCourseId ( element . KURS_ID ) . subscribe ( responseCourse => {
52+ responseCourse . ANM_DATUM = element . ANM_DATUM ;
53+ this . courses . push ( responseCourse ) ;
5554 } ) ;
5655 } ) ;
57- if ( response . name != "HttpResponseError" ) {
56+ if ( responseUser . name != "HttpResponseError" ) {
5857 this . dataIsAvailable = true ;
5958 }
6059 } ) ;
6160 }
6261
6362 requestCoursesByCategory ( courseId : string ) :void {
6463 this . headerText = this . category ;
65- this . categoryService . getCoursesByCategoryId ( courseId ) . subscribe ( response => {
66- this . courses = response ;
64+ this . courses = [ ] ;
65+ this . categoryService . getCoursesByCategoryId ( courseId ) . subscribe ( response => {
66+ this . courses . push ( response ) ;
6767 if ( response . name != "HttpResponseError" ) {
6868 this . dataIsAvailable = true ;
6969 this . courses = response ;
0 commit comments