Javascript 角度11 HTML标记<;脚本>;相等的
在asp.net中,我曾经使用此代码Javascript 角度11 HTML标记<;脚本>;相等的,javascript,html,angular,templates,Javascript,Html,Angular,Templates,在asp.net中,我曾经使用此代码 <div> <script type="text/javascript" src="https://www.europetnet.org/epn-badge.js?IDC,grey"></script> </div> ngOnInit() { this.script = this.renderer2.createElement("script&
<div>
<script type="text/javascript" src="https://www.europetnet.org/epn-badge.js?IDC,grey"></script>
</div>
ngOnInit() {
this.script = this.renderer2.createElement("script");
this.script.type = "text/javascript";
this.script.src = "https://www.europetnet.org/epn-badge.js?IDC,grey";
this.script.text = ``;
this.renderer2.appendChild(this.document.body, this.script);
我不知道如何在html模板中使用它。如果您要包含一个永久性的应用程序外部库,您可以在我的旧应用程序的angular index.html文件中包含该标记(作为body标记中的最后一个元素),该标记就是这样显示的。请参阅vet.idchips.com,左边的Europenet徽章第一:您没有指定在wich组件中使用的ngOnInit?我想是在app.component中,第二,你没有指定你的脚本是动态的(可更改的)还是静态的(不可更改的),最后:我建议使用document.createElement(..)而不是rendrer,看看这是否可行
ngOnInit() {
this.script = this.renderer2.createElement("script");
this.script.type = "text/javascript";
this.script.src = "https://www.europetnet.org/epn-badge.js?IDC,grey";
this.script.text = ``;
this.renderer2.appendChild(this.document.body, this.script);