【问题标题】:Calendly Widget not working in IE (Angular App)Calendly Widget 在 IE(Angular 应用程序)中不起作用
【发布时间】:2019-05-03 16:38:00
【问题描述】:

我将 Calendly 小部件嵌入到一个简单的 Angular 应用程序中。它适用于 Chrome、Firefox 和 Edge,但在 IE 中仅显示一个空白框。

该网站的工作网址是https://cei-demo.firebaseapp.com/schedule-an-appointment

我尝试过使用 innerHTML 从组件而不是模板中呈现 HTML 代码。我遇到了同样的问题。

calendly.component.html

<div class="my-5 p-3 container bg-white text-dark">
  <div class="calendly-inline-widget" data-url="https://calendly.com/test-cei" style="min-width:320px;height:700px;"></div>
</div>

index.html(body 标签的正上方)

<script type="text/javascript" src="https://assets.calendly.com/assets/external/widget.js"></script>

我希望小部件显示在所有浏览器中。

下面是响应 Dmitry Pashkevich 的代码:

组件.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-calendly',
  templateUrl: './calendly.component.html',
  styleUrls: ['./calendly.component.css']
})
export class CalendlyComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }
}

component.html

<div class="my-5 p-3 container bg-white text-dark">
  <div class="calendly-inline-widget" style="min-width:320px;height:580px;" data-auto-load="false">
</div> 

index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Carbon Emery Insurance</title>
  <base href="/">
  <!-- reCaptcha -->
  <script src="https://www.google.com/recaptcha/api.js" async defer></script>

  <!-- Custom Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Lato|Montserrat" rel="stylesheet">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="./assets/favicon.ico">

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">

</head>
<body>
  <app-root></app-root>

  <!-- Bootstrap js -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  <script type="text/javascript" src="https://assets.calendly.com/assets/external/widget.js"></script>
  <script>
    Calendly.initInlineWidget({
    url: 'https://calendly.com/test-cei',
    parentElement: document.querySelector('.calendly-inline-widget'),
    });
  </script>
</body>
</html>

【问题讨论】:

    标签: internet-explorer angular6 calendly


    【解决方案1】:

    欢迎来到 StackOverflow,@wingej0。

    有一个特殊的 JavaScript API,用于从 Angular、React 等中的单页应用程序调用 Calendly 小部件。使用此 API,您可以准确控制想要初始化小部件的时间,而不是让它在页面加载时初始化.

    一般说明

    首先,将data-auto-load="false" 属性添加到.calendly-inline-widget 并删除data-url 属性。所以元素应该是这样的:

    <div class="calendly-inline-widget" style="min-width:320px;height:580px;" data-auto-load="false">
    

    然后,在你想要初始化 Calendly 小部件之后执行此代码:

    Calendly.initInlineWidget({
     url: 'https://calendly.com/test-cei',
     parentElement: document.querySelector('.calendly-inline-widget'),
    });
    

    更多文档在这里:Calendly Advanced embed options

    将其包装在 Angular 组件中

    如上所述,为了动态创建 Calendly 嵌入小部件,我们需要两件事:

    1. 创建一个容器元素,Calendly 嵌入 API 将在其中呈现 Calendly iframe
    2. 调用 Calendly Embed API

    这两件事在一个组件中完美结合:

    import { 
        Component, 
        NgModule, 
        VERSION, 
        ElementRef,
        ViewChild
    } from '@angular/core'
    
    @Component({
      selector: 'app-calendly-widget',
      template: `
            <div #container class="calendly-inline-widget" style="min-width:320px;height:580px;" data-auto-load="false"></div>
      `
    })
    export class CalendlyWidgetComponent {
        @ViewChild('container') container: ElementRef;
    
        ngOnInit() {
          Calendly.initInlineWidget({
            url: 'https://calendly.com/test-cei',
            parentElement: this.container.nativeElement
          });
        }
    

    上面的代码(TypeScript)定义了一个渲染容器并在初始化时立即调用 Calendly Embed API 的组件。我们使用Angular's @ViewChild 来访问组件呈现的原始DOM 元素。

    这是一个工作演示:https://plnkr.co/edit/mpl6l8ifxc1amS611DMD?p=preview(请注意,它使用的 Angular 版本比您使用的旧版本,如果您有兼容性问题,请告诉我)

    【讨论】:

    • 感谢您的帮助。我只有几分钟的时间来修改这个,而且我对 Angular 和 JavaScript 还是很陌生。因此,我尝试将第二组代码放入 index.html 和我的组件模板中的脚本标记中,并且我还尝试将其编码到组件中的 ngOnInit 中。两者似乎都不起作用。我不熟悉如何将常规 Javascript 添加到 Angular 项目中。您能提供的任何建议将不胜感激。
    • 我已将其添加到 OP。我尝试了其他一些方法,但它们都不起作用或看起来特别合乎逻辑。理想情况下,我会将脚本添加到 component.ts 文件中,但我不知道该怎么做,甚至不知道是否可行。再次感谢。这看起来应该很简单,但它一直是一个令人头疼的问题。
    • 由于没有找到 Calendly 对象的强输入,任何人仍然遇到问题,只需将 export {};声明全局{界面窗口{日历:任何; } } 在 globals.ts 上
    猜你喜欢
    • 2017-01-24
    • 2011-09-25
    • 1970-01-01
    • 2018-03-22
    • 2019-01-23
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多