admin管理员组文章数量:1417684
I'm trying to embed a calendly widget into my angular app, but I find that it doesn't work consistently.
Firstly I add this line to my ponent's HTML:
<div class="calendly-inline-widget" data-url="; style="min-width:320px;height:630px;"></div>
and this line to the index.html:
<script src=".js" async></script>
This works initially but then the embedded calendar vanishes whenever the page reloads.
By reading the Advanced Embed Options in Calendly's documentation, I attempted a slightly different approach, where my ngOnInit()
function looks like this:
ngOnInit(): void {
Calendly.initInlineWidget({
url: '',
parentElement: document.querySelector('.calendly-inline-widget'),
});
}
and I've also added data-auto-load="false"
to the div in the HTML, but I get the error message "Cannot find name 'Calendly'" and I'm unsure where Calendly should be declared or imported from.
Any suggestions on how I can get the calendar working?
I'm trying to embed a calendly widget into my angular app, but I find that it doesn't work consistently.
Firstly I add this line to my ponent's HTML:
<div class="calendly-inline-widget" data-url="https://calendly./my-calendar-link" style="min-width:320px;height:630px;"></div>
and this line to the index.html:
<script src="https://assets.calendly./assets/external/widget.js" async></script>
This works initially but then the embedded calendar vanishes whenever the page reloads.
By reading the Advanced Embed Options in Calendly's documentation, I attempted a slightly different approach, where my ngOnInit()
function looks like this:
ngOnInit(): void {
Calendly.initInlineWidget({
url: 'https://calendly./my-calendar-link',
parentElement: document.querySelector('.calendly-inline-widget'),
});
}
and I've also added data-auto-load="false"
to the div in the HTML, but I get the error message "Cannot find name 'Calendly'" and I'm unsure where Calendly should be declared or imported from.
Any suggestions on how I can get the calendar working?
Share Improve this question asked Jul 28, 2021 at 12:13 Scotland141Scotland141 3453 silver badges14 bronze badges 2- blog.knoldus./… Does this help? – Anglesvar Commented Jul 28, 2021 at 12:53
- That's the article I used initially but it doesn't fix it for me unfortunately. The article describes 2 methods - the first one I describe copying exactly above (that's the one with the div in the HTML and the script in the index.html). The second one requires downloading the Calendly script file, but this contains a Calendly variable, and then I run into the other problem I mention in the question where I get "Cannot find name Calendly" again. – Scotland141 Commented Jul 28, 2021 at 12:57
2 Answers
Reset to default 5I've managed to get this working by adding the following:
export {}; declare global { interface Window { Calendly: any; } }
and then changing ngOnInit()
to :
ngOnInit(): void {
window.Calendly.initInlineWidget({
url: 'https://calendly./my-calendar-link',
parentElement: document.querySelector('.calendly-inline-widget'),
});
}
Credit to ment here Calendly Widget not working in IE (Angular App)
This still gave me errors when reloading the page, so I, not being either an expert Angular nor Javascript developer, did an ugly workaround based on the helpful answer already given in order to force the Calendly object to always be there when I need it. I'll leave it here for whom it might be useful for.
Copied the external javascript file https://assets.calendly./assets/external/widget.js to
src/assets/js/calendly.js
Removed the implicit anonymous function call and wrapped the whole damned thing in a named function - not called immediately, like so:
function preInitCalendly() { console.debug('Calendly pre-initialization for ' + this); this.Calendly = {}; this.Calendly._util = {}; Calendly._util.domReady = function(callback) { ... }; ... and the rest, all the way to the end of the file ... }
Removed the final
Calendly._autoLoadInlineWidgets()
Added src/assets/js/calendly.js to the
"scripts"
in angular.jsonAdded the script to index.html
Call the shite in the onInit part of the ponent
index.html
...
<head>
...
<script async src="assets/js/calendly.js"></script>
</head>
...
calendly.ponent.html
<div class="calendly-inline-widget" data-auto-load="false"></div>
calendly.ponent.ts
export {};
declare global {
interface Window {
Calendly: any;
}
}
declare var preInitCalendly: Function;
@Component({
selector: 'app-calendly',
templateUrl: './calendly.ponent.html',
styleUrls: ['./calendly.ponent.css']
})
export class CalendlyComponent implements OnInit {
url = 'https://calendly./my_calendly_location';
constructor() {
}
ngOnInit(): void {
preInitCalendly();
window.Calendly.initInlineWidget({
url: this.url,
parentElement: document.querySelector('.calendly-inline-widget'),
prefill: {}
});
}
It's not pretty, but it seems to be working reliably.
本文标签: javascriptHow to embed Calendly with Angular 12Stack Overflow
版权声明:本文标题:javascript - How to embed Calendly with Angular 12 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745275704a2651172.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论