加载外部JavaScript的Angular2问题 [英] Angular2 issues to load external javascripts
问题描述
我是agnular2的新手.我使用了html5主题和具有多个javascript文件的主题.现在的问题是我试图将文件加载到我的angular2应用程序中,但是加载不正确.
I am new in agnular2. I have used html5 theme and theme having multiple javascript files. Now the issue is I am trying to load that files in my angular2 app but it's not loading properly.
我所做的只是将脚本链接到我的index.html文件,并且第一次打开页面时脚本运行良好,但是当我在应用程序中路由页面时,则不会将其加载到每个应用程序中路由器更改需要刷新页面.
What I have did is just link up that scripts to my index.html file and first time when I open the page the scripts are working good but when I route the pages in my app then it's not loading into the app on each router change need to refresh the page.
请帮助.. !!!
推荐答案
我认为您需要在自己的视图上对其进行初始化.我已经做了类似的事情:
I think you need to initialise it on your view.I have done something like this:
在app.js(已包含在index.html中)
In app.js(which i have included in my index.html)
function scrollToId(id){
//scroll fn
}
在我看来/组件从'@ angular/core'导入{Component,OnInit};
In my view/Component import { Component, OnInit } from '@angular/core';
declare var scrollToId: any;
@Component({})
export class UserDetailsComponent implements OnInit {
constructor(){}
ngOnInit() {
new scrollToId('registration-form');
}
}
&对我来说很好.
& it's working fine for me.
这篇关于加载外部JavaScript的Angular2问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!