1

我想在我的 Angular 应用程序中放置 3 个 trustPilots。

import { Component, Input, OnInit } from '@angular/core';
declare global {
    interface Window { Trustpilot: any; }
}
 
window.Trustpilot = window.Trustpilot || {};

@Component({
    selector: 'app-trustbox-normal',
    templateUrl: './trustbox-normal.component.html',
    styleUrls: ['./trustbox-normal.component.scss']
})
export class TrustboxNormalComponent implements OnInit {

    constructor() { }

    ngOnInit(): void { }

    ngAfterViewInit(){
        const trustboxRef = document.getElementById('trustbox');
        window.Trustpilot.loadFromElement(trustboxRef);
    }

}

在 Brave 上,Firefox 运行良好,但在 Safari 中出现错误:
window.Trustpilot.loadFromElement 不是函数。(在 'window.Trustpilot.loadFromElement(trustboxRef)' 中,'window.Trustpilot.loadFromElement' 未定义)

4

2 回答 2

0

可能与Next.js 中的这个 Trustpilot TrustBoxes 有关

您是否尝试过为 loadFromElement 的调用添加延迟以给 Truspilot js 脚本加载足够的时间?

于 2022-01-04T13:59:15.473 回答
0

window.Trustpilot = window.Trustpilot || {};从代码中删除了,现在它在 Safari 上也可以正常工作。

于 2022-01-28T17:18:51.033 回答