import {Component, Input, ElementRef} from '@angular/core'; @Component({ selector: 'showIdentifiers', template: ` View less identifiers {{key}}: {{item}}{{key}}: {{item}}{{key}}: {{item}}{{", "}} ... view all {{countIdentifiers() | number}} identifiers View less identifiers ` }) export class ShowIdentifiersComponent { @Input() identifiers: Map; public doiURL: string; public pmcURL: string; public handleURL: string; public showAll: boolean = false; public sizeOfIdentifiers: number = -1; public sizeOfPreviousIdentifiers: number = -1; public pageSize: number = 10; constructor (private element: ElementRef) { this.doiURL = "https://dx.doi.org/"; this.pmcURL = "http://europepmc.org/articles/"; this.handleURL = "http://hdl.handle.net/"; } ngOnInit() {} public countIdentifiers(): number { if(this.sizeOfIdentifiers < 0) { let num: number = 0; if(this.identifiers != undefined) { this.identifiers.forEach(function (value, key, map) { num += value.length; }); } this.sizeOfIdentifiers = num; } return this.sizeOfIdentifiers; } public countSizeOfPreviousIdentifiers(index: number): number { let num: number = 0; let i: number = 0; if(this.identifiers != undefined) { this.identifiers.forEach(function (value, key, map) { if(i < index) { num += value.length; } i++; }); } this.sizeOfPreviousIdentifiers= num; return num; } public scroll() { console.info("scroll into view"); if (typeof document !== 'undefined') { this.element.nativeElement.scrollIntoView(); } } public getKeys( map) { return Array.from(map.keys()); } }