我正在尝试使用angular重写网站,并且有一个页面使用不同的脚本集,因此我无法使用当前的index.html,因为它没有必要加载,因为它没有必要js文件
那么是否可以根据路由有条件地添加/删除脚本?例如,如果我在这条路线上,我想将此脚本文件添加到index.html
答案 0 :(得分:0)
import { ActivatedRouteSnapshot } from '@angular/routing';
constructor(route: ActivatedRoute){}
ngOnInit() {
const script = document.createElement('script');
script.src ='../../assets/js/myScript.js';
if (this.route === 'root/with/script') {
document.body.appendChilde(script);
}
}