import { Component, OnInit } from '@angular/core'; import { IsService } from '../is.service'; import { ResourceIdentification, TYPE_PROPERTY_KEY } from './resourceidentification'; @Component({ selector: 'app-resource-list', templateUrl: './resource-list.component.html', styleUrls: ['./resource-list.component.css'] }) export class ResourceListComponent implements OnInit { public resourceIdentificationList: Array; constructor(private isService: IsService) { } ngOnInit() { // this.isService.getIdentifyingFacets('Service', facets => {this.identifyingFacets = facets;}); this.isService.getIdentifyingFacets('Service', facets => { this.resourceIdentificationList = this.analyseIdentifyingFacets(facets); }); } analyseIdentifyingFacets(identifyingFacets: any[]): Array { const map = new Map(); const facets = new Array(); for (const facet of identifyingFacets) { const facetType: string = facet[TYPE_PROPERTY_KEY]; let facetList: ResourceIdentification; if (map.has(facetType)) { facetList = map.get(facetType); } else { facetList = new ResourceIdentification(facetType); map.set(facetType, facetList); facets.push(facetList); } facetList.add(facet); } return facets; } }