Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取未定义的错误,即使在angular中声明变量为declare var xyz_Angular_Typescript_Chat - Fatal编程技术网

获取未定义的错误,即使在angular中声明变量为declare var xyz

获取未定义的错误,即使在angular中声明变量为declare var xyz,angular,typescript,chat,Angular,Typescript,Chat,看起来您正在声明变量WhWidgetSendButton,但从未对其进行设置 本质上,WhWidgetSendButton=undefined,然后您试图对未定义的变量调用.init(主机、协议、选项) 调用init之前,需要将WhWidgetSendButton设置为类似WhWidgetSendButton=new WhWidgetSendButton()的值,错误为“WhWidgetSendButton未定义”,与未定义的变量WhWidgetSendButton不同,它在代码中的任何地方都不

看起来您正在声明变量
WhWidgetSendButton
,但从未对其进行设置

本质上,
WhWidgetSendButton=undefined
,然后您试图对未定义的变量调用
.init(主机、协议、选项)


调用
init
之前,需要将
WhWidgetSendButton
设置为类似
WhWidgetSendButton=new WhWidgetSendButton()

的值,错误为“WhWidgetSendButton未定义”,与未定义的变量WhWidgetSendButton不同,它在代码中的任何地方都不会被设置——它看起来像是您试图利用的库,但
var WhWidgetSendButton将其设置为未定义。这样想吧<代码>变量x
x.doSomething()
永远不会工作,因为
x
从未被实例化(或定义)。不过,这是可行的:
varx=newsomeclass();x、 doSomething()
因为定义了
x
declare
var WhWidgetSendButton;

ngOnInit() {
  var options = {
    facebook: "xxxx", // Facebook page ID
    whatsapp: "xxx", // WhatsApp number
    call_to_action: "Message us", // Call to action
    button_color: "#008000", // Color of button
    position: "left", // Position may be 'right' or 'left'
    order: "whatsapp,facebook", // Order of buttons
  };
  var proto = document.location.protocol;
  var host = "whatshelp.io";
  var url = proto + "//static." + host;
  let s = document.createElement('script');
  s.type = 'text/javascript';
  s.async = true;
  s.src = url + '/widget-send-button/js/init.js';

  s.onload = () => {
    WhWidgetSendButton.init(host, proto, options);
  };
  let x = document.getElementsByTagName('script')[0];
  x.parentNode.insertBefore(s, x);
}