我将Calendly小部件嵌入到一个简单的角应用程序中。它适用于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 (就在主体标签上方)
<script type="text/javascript" src="https://assets.calendly.com/assets/external/widget.js"></script>我希望小部件能在所有浏览器中显示。
下面是针对Dmitry Pashkevich的代码:
component.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>发布于 2019-05-03 18:20:52
欢迎来到StackOverflow @wingej0 0。
有一种特殊的JavaScript API用于从单页应用程序调用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高级嵌入选项
把它包裹在一个角度分量中
如上所述,为了动态创建Calendly嵌入小部件,我们需要两件事:
这两件事完美地结合在一个组件中:
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。我们使用@ViewChild访问组件呈现的原始DOM元素。
下面是一个工作演示:https://plnkr.co/edit/mpl6l8ifxc1amS611DMD?p=preview (请注意,它使用的是比您使用的更早版本的issues,如果您有兼容性问题,请告诉我)
https://stackoverflow.com/questions/55973983
复制相似问题