Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在angular 4中加载特定路由的脚本_Javascript_Angular - Fatal编程技术网

Javascript 如何在angular 4中加载特定路由的脚本

Javascript 如何在angular 4中加载特定路由的脚本,javascript,angular,Javascript,Angular,我必须加载一个脚本来计算angular 4中特定路线的分析。但对于其他路由,不应加载脚本 我尝试在index.html中添加脚本,但将为所有路由加载脚本。有解决办法吗 下面是脚本 (功能(a、b、c、d、e、f){ a、 hj=a.hj | | function(){(a.hj.q=a.hj.q |[]).push(arguments)}; a、 _hjSettings={hjid:xx,hjsv:xxx}; e=b.getElementsByTagName('head')[0]; f=b.cr

我必须加载一个脚本来计算angular 4中特定路线的分析。但对于其他路由,不应加载脚本

我尝试在index.html中添加脚本,但将为所有路由加载脚本。有解决办法吗

下面是脚本

(功能(a、b、c、d、e、f){
a、 hj=a.hj | | function(){(a.hj.q=a.hj.q |[]).push(arguments)};
a、 _hjSettings={hjid:xx,hjsv:xxx};
e=b.getElementsByTagName('head')[0];
f=b.createElement('script');f.async=1;
f、 src=t+a.hjSettings.hjid+d+a.hjSettings.hjsv;
e、 儿童(f);
})(窗口、文件、https://xx.xx.com/c/xx-“,”.js?sv=”);

如果将脚本添加到
index.html
中,则脚本将加载到
所有组件中,这不是您需要的。因此,您可以尝试从要加载脚本的组件的
ts文件
加载脚本。因此,在
ts文件中
,您可以按如下操作

System.import('https://xx.xx.com/c/xx-','.js?sv='); //or below one
require('https://xx.xx.com/c/xx-','.js?sv=');
参考: