我希望是个简单的问题。
我希望在触发$document.ready()的Angular2等效项时运行脚本。实现这一目标的最佳方法是什么?
我试着将脚本放在index.html
的末尾,但我发现这不起作用!我认为它必须放在某种组件声明中?
是否可以从.js
文件中运行加载脚本?
编辑-代码:
我已经将以下js和css插件注入到我的应用程序中(从Foundry html theme)。
<link href="css/themify-icons.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
...
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/flexslider.min.js"></script>
...
<script src="js/scripts.js"></script> //This initiates all the plugins
正如前面提到的,scripts.js“实例化”了整个过程,因此需要在Angular准备好之后运行。script.js
让它工作了:
import {Component, AfterViewInit} from 'angular2/core';
@Component({
selector: 'home',
templateUrl: './components/home/home.html'
})
export class HomeCmp implements AfterViewInit {
ngAfterViewInit() {
//Copy in all the js code from the script.js. Typescript will complain but it works just fine
}
https://stackoverflow.com/questions/34547127
复制相似问题