I need to rewrite/adapt a JS method so I can run an old JS script into a new Angular app.
boot: function() {
var that = this;
that.container = document.getElementById('embedded_messenger');
that.chatClient = document.getElementById('chat_client').contentWindow;
window.addEventListener('message', that.receiveMessage, false);
return this;
}
Usually, this boot method is called just after the script has been loaded into the HTML page.
<body>
...
<script src="embed.js"></script>
<script>
var options = {};
Chat.boot();
</script>
</body>
In an Angular app, should I call the boot function inside
ngOnInit()
to get the same behaviour as previously with the HTML document ?var that = this
is explained here but my question is aboutreturn this;
: isthat
returned ? Isthat
a clone of (or a reference to)this
?that.container = document.getElementById('embedded_messenger');
generates an error during Angular compilation : Property 'container' does not exist
Is it a good practice to use @ViewChild('embedded_messenger')
to replace getElementById('embedded_messenger')
or is it better to use Angular elements ?
- Same question about
addEventListener
: should I use Angular EventManager to replace it ?
Many thanks for your advices.