简体   繁体   English

角度js代码无法与外部插件一起使用

[英]angular js code not working with external plugin

  • I am trying to use intercom in my app to monitor user activity. 我正在尝试在我的应用程序中使用对讲机来监视用户活动。
  • its working fine when I put inside script tag in index.html 当我将脚本标记放入index.html时,它的工作正常
  • but when I try to use in .ts file I am getting below error. 但是当我尝试在.ts文件中使用时,出现以下错误。 app/components/rocket/rocket-search.ts(63,10): error TS2339: Property 'intercomSettings' does not exist on type 'Window'. app / components / rocket / rocket-search.ts(63,10):错误TS2339:属性“ intercomSettings”在“窗口”类型上不存在。
  • can you tell me how to fix it. 你能告诉我如何解决它。
  • providing my code below 在下面提供我的代码

not working code 不起作用的代码

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);
    }

}

working code inside index.html 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>

well it wouldn't work, the code in your html actually fetches the intercom js library from the URL https://widget.intercom.io/widget/APP_ID which the code in your typescript do not. 嗯,这是行不通的,您的html中的代码实际上是从URL https://widget.intercom.io/widget/APP_ID提取对讲机js库的,而打字稿中的代码则无法。 A better approach is to install the intercom npm package that you can then import in your code, however I don't write typescript so I'm unsure if there would be any issue using the package in a typescript fashion. 更好的方法是安装对讲机npm软件包 ,然后将其导入您的代码中,但是我不编写打字稿,因此我不确定以打字稿的方式使用该包是否会出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM