Имеется глобальный сервис, внутри которого хранятся переменные и методы. Если проверить отдельные переменные (массивы), то они отображаются в консоли. Но среди всех переменных есть два массива (parts и categories), которые не отображаются отдельно (показывает пустой массив). При этом если проверить содержимое всего сервиса через console.log можно увидеть всё, что есть внутри (в том числе и те массивы, которые по отдельности не отображаются).
Вот код сервиса:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class GlobalSeviceService {
animals: Animal[] = [];
genders: Gender[] = [];
myAnimal: MyAnimal = {animal_id: 0, gender_id: 0};
menu_items: Menu[] = [];
categories: Category[] = [];
parts: Part[] = [];
actual_categ_id: number;
non_changeable_parts_svg = [];
constructor_resp: any;
constructor(public http: HttpClient) {
}
transferGenderId(b){
this.myAnimal.gender_id = b;
}
transferConstructorData(anim_id, gender_id){
this.http.get<Category[]>('http://localhost:8000/constructor_page?anim_id=' + anim_id
+ "&gender_id=" + gender_id)
.subscribe(response => {
this.constructor_resp = response;
this.categories = this.constructor_resp.constructor_page['categ_parts'];
this.parts = this.constructor_resp.constructor_page['parts'];
let j;
let i = 0;
for (j in this.categories) {
if (this.categories[j].changeable){
i ++;
if (i === 1){
this.categories[j].css_categ_active = true;
}
else {
this.categories[j].css_categ_active = false;
}
}
}
});
}
}
Пробую выводить в консоли внутри компонента:
import {Component, OnInit} from '@angular/core';
import { PetComponent } from '../pet/pet.component';
import {GlobalSeviceService, Part} from '../services/global-sevice.service';
@Component({
selector: 'app-constructor-page',
templateUrl: './constructor-page.component.html',
styleUrls: ['./constructor-page.component.scss']
})
export class ConstructorPageComponent implements OnInit {
constructor(
public globalService: GlobalSeviceService) {
}
ngOnInit(): void {
}
ngAfterViewInit() {
console.log(this.globalService.parts);
console.log(this.globalService);
}
}
anim_id и gender_id берутся от выбора пользователя.
В общем, если у вас есть предположение, почему не отображаются массивы в консоли, буду признателен за помощь.
