gpt4 book ai didi

javascript - Angular js代码无法与外部插件一起使用

转载 作者:行者123 更新时间:2023-11-28 03:48:06 25 4
gpt4 key购买 nike

  • 我正在尝试在应用中使用对讲机来监控用户事件。
  • 当我将脚本标签放入index.html时,它工作正常
  • 但是当我尝试在 .ts 文件中使用时,出现以下错误。app/components/rocket/rocket-search.ts(63,10): 错误 TS2339: 类型“Window”上不存在属性“intercomSettings”。
  • 你能告诉我如何解决这个问题吗?
  • 在下面提供我的代码

代码不工作

import { Component, ElementRef, Input, Output, EventEmitter, Inject, OnInit, ViewChild } from '@angular/core';
import { KendoGridComponent } from '../grid/grid.component'
import { Router } from '@angular/router';
import { sportsService } from '../../services/sports.service';


@Component({
selector: 'rocketSearch',
templateUrl: "./app/components/rocket/rocket-search.html",
})

export class rocketSearch {
/* Localization variables */

@Output() rocketSearchEmitter: EventEmitter<any> = new EventEmitter<any>();

private dataSourceVal;
private MainGrid;
private grid;
private titles;
public rocketRef;

constructor( public elementRef: ElementRef, public router: Router, public sportsService: sportsService) {
}
private kendocommand = {
edit: { createAt: "bottom" },
autoBind: false,
excelFileName: {
fileName: "",
allPages: true
}
}

ngOnInit() {

let that = this;
let attributes = this.sportsService.getSeesionStorageValue();
// if (attributes) {
// this.userId = attributes.user_attributes.SSO[0];
// }

//app/components/rocket/rocket-search.ts(63,10): error TS2339: Property 'intercomSettings' does not exist on type 'Window'.


window.intercomSettings = {
app_id: 'irgooiqb',
name: "Jane Doe", // Full name
email: "customer@example.com", // Email address
created_at: 1312182000 // Signup date as a Unix timestamp
};
//console.log(.log(this.userId);
}

}

index.html 内的工作代码

<script>
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/APP_ID';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()
</script>

<script>
let players=this.sportsService.marksSession();
console.log("players--->" + players);
if(players) {
this.userId = players.user_players.SSO[0];
}

Intercom('trackEvent', 'share-link');

window.intercomSettings = {
app_id: 'APP_ID',
name: "Jane Doe", // Full name
email: "customer@example.com", // Email address
created_at: 1312182000 // Signup date as a Unix timestamp
};
</script>

最佳答案

好吧,这是行不通的,你的html中的代码实际上从URL https://widget.intercom.io/widget/APP_ID获取对讲js库,其中你的 typescript 中的代码不要。更好的方法是安装 intercom npm package然后您可以将其导入代码中,但是我不编写 typescript ,因此我不确定以 typescript 方式使用该包是否会出现任何问题。

关于javascript - Angular js代码无法与外部插件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48271145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com