Angular 角度:属性';xxx和x27;不存在于类型';窗口及;globalThis'的类型;
在为我的应用程序提供服务后,我收到命令行中添加的Trustbox组件ts文件的问题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';
"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上工作,您必须
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已成功更新!!!”;
}
}