All files / app/elements/trustbox trustbox.component.ts

86.2% Statements 25/29
50% Branches 2/4
100% Functions 2/2
86.2% Lines 25/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 301x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x     1x 1x 1x  
import { isPlatformBrowser } from '@angular/common';
import { Component, OnInit, PLATFORM_ID, inject } from '@angular/core';
 
declare let window: any;
 
@Component({
	selector: 'grt-trustbox',
	templateUrl: './trustbox.component.html',
	styleUrls: ['./trustbox.component.scss'],
	standalone: true,
})
export class TrustboxComponent implements OnInit {
	private platformId = inject(PLATFORM_ID);
 
	ngOnInit() {
		if (isPlatformBrowser(this.platformId)) {
			const elements = document.getElementsByClassName('trustpilot-widget');
			if (elements.length > 0) {
				for (let i = 0; i < elements.length; i++) {
					if (window.Trustpilot) {
						window.Trustpilot.loadFromElement(elements[i]);
					}
				}
			} else {
				console.error('No elements with class name "trustpilot-widget" found');
			}
		}
	}
}