angular script widget not showing
I have a working widget which renders fine in html.
<div id='mobilum-widget'></div>
<script src='https://widget-dev.mobilum.com/js/app.js'></script>
I know angular removes script tag from component html, so this is what I tried:
app.component.html
<div id='mobilum-widget'></div>
app.component.ts
import { Component, VERSION, AfterViewInit, Renderer2 } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
constructor(private renderer: Renderer2, private sanitizer: DomSanitizer) {}
ngAfterViewInit() {
const script = this.renderer.createElement('script');
script.async = true;
script.type = 'text/javascript';
script.src = this.sanitizer.bypassSecurityTrustScript(
"<script src='https://widget-dev.mobilum.com/js/app.js'></script>"
);
var mobilum_widget = document.getElementById('mobilum-widget');
this.renderer.appendChild(mobilum_widget, script);
}
}
this still won't show, not sure what the problem is.
from Recent Questions - Stack Overflow https://ift.tt/34m8ZmV
https://ift.tt/eA8V8J
Comments
Post a Comment