Angular 角度:属性';xxx和x27;不存在于类型';窗口及;globalThis'的类型;

Angular 角度:属性';xxx和x27;不存在于类型';窗口及;globalThis'的类型;,angular,typescript,Angular,Typescript,在为我的应用程序提供服务后,我收到命令行中添加的Trustbox组件ts文件的问题 "Property 'Trustpilot' does not exist on type 'Window & typeof globalThis'." 我曾试图宣布这个窗口,并在世界各地寻找解决办法,但我一生都无法找到它 这是trustbox.component.ts代码 import { Component, OnInit } from '@angular/core';

在为我的应用程序提供服务后,我收到命令行中添加的Trustbox组件ts文件的问题

    "Property 'Trustpilot' does not exist on type 'Window & typeof globalThis'."
我曾试图宣布这个窗口,并在世界各地寻找解决办法,但我一生都无法找到它

这是trustbox.component.ts代码

import { Component, OnInit } from '@angular/core';
@Component({
  selector: 'app-trustbox',
  templateUrl: './trustbox.component.html',
})
export class TrustboxComponent implements OnInit {
  constructor() {}
  ngOnInit() {
    const trustboxRef = document.getElementById('trustbox');
    window.Trustpilot.loadFromElement(trustboxRef);
  }
}
根据Trustpilot文章()的说法,要让他们的小部件在SPA上工作,您必须

  • 实现OnInit
  • 获取对我们先前粘贴的元素的引用
  • 调用loadFromElement函数
  • 我知道这可能很简单,但它非常烦人,因为我无法编译我的应用程序。非常感谢您的帮助。提前谢谢

    使用@,获取引用并对其进行处理,使用AfterViewInit仅在读卡器完成并在屏幕上创建组件后使用

    例如:

    import { Component, ViewChild, AfterViewInit, ElementRef } from "@angular/core";
    
    @Component({
      selector: "my-app",
      template: `
        <p #pRef>
          Start editing to see some magic happen :)
        </p>
      `,
      styleUrls: ["./app.component.css"]
    })
    export class AppComponent implements AfterViewInit {
      name = "Angular";
    
      @ViewChild("pRef", { static: false }) pRef: ElementRef;
    
      ngAfterViewInit() {
        console.log(this.pRef.nativeElement.innerHTML);
        this.pRef.nativeElement.innerHTML = "DOM updated succesfully!!!";
      }
    }
    
    从“@angular/core”导入{Component,ViewChild,AfterViewInit,ElementRef};
    @组成部分({
    选择器:“我的应用程序”,
    模板:`
    
    开始编辑以查看发生的奇迹:)
    

    `, 样式URL:[“/app.component.css”] }) 导出类AppComponent实现AfterViewInit{ name=“Angular”; @ViewChild(“pRef”,{static:false})pRef:ElementRef; ngAfterViewInit(){ log(this.pRef.nativeElement.innerHTML); this.pRef.nativeElement.innerHTML=“DOM已成功更新!!!”; } }