如何在每个组件中加载jQuery脚本?

时间:2017-02-02 08:53:46

标签: jquery angular

我使用Angular2和Limitless布局构建单页面应用程序。 但是,主题中有一个包含所有jQuery功能的app.js文件。 我已经将它加载到index.html中,但jQuery仅在我刷新页面时才有效。

如何修改app.js以使jQuery函数在每个组件中运行?

2 个答案:

答案 0 :(得分:0)

app.js中创建函数ie。

function executeEveryCompo(){
      console.log('Something');
}

并在每个组件AfterviewInit中添加

ngAfterviewInit(){
     executeEveryCompo();
}

不要忘记在组件顶部添加declare var executeEveryCompo:any;

答案 1 :(得分:0)

在Component Decorator之前,使用

// You can use $ to refer to jQuery inside the code
declare var $ : any;

@Component({
  selector: 'my-selector',
  providers: []
})
相关问题