I want to include the Telegram login widget in my Angular application. For this, you have to include the following script:
<script async src="https://telegram.org/js/telegram-widget.js?5"
data-telegram-login="bot_name" data-size="large"
data-auth-url="https://myurl.example/api/telegram"
data-request-access="write"></script>
Embedding scripts in Angular templates is not allowed, it will just be removed. (However, it is possible to include a script tag via this hack.)
Is there a non-hacky way of including this widget?
2
Answers
I created the following component for the Telegram login widget:
The component creates the script tag dynamically and adds the callback function
loginViaTelegram(user)
:I added the callback function
loginViaTelegram
to thewindow
object (global space) in a dedicated service:Not rendering
script
tags in template code is indeed a design choice from Angular team.The way to do it is thus:
head
is not suitable unless you remove it inOnDestroy
. Prefer adding in the right DOM element of your component.