繁体   English   中英

如何在Angular2组件之前加载其他文件

[英]How to load other file(s) before Angular2 components

是否可以在Angular 2加载之前加载特定文件? 目前,我正在angular-cli.json全局加载jQuery, bootstrap, file.js angular-cli.json包括它,当您启动Angular时,它会捆绑在一起。

是否可以在Angular之前先加载file.js 我还需要加载jQuery的这个file.js ,因为它有一些jQuery的http请求。 我尝试将../node_modules/jQueryangular-cli.json移到index.html。

Angular-cli.json-当file.js位于angular-cli.json中时

"scripts": [
    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/bootstrap/dist/js/bootstrap.js",
    "./assets/js/file.js"
  ],

index.html-当我在索引中移动jQuery和file.js时,我得到的jQuery未定义。

// in head tag
<script src="../node_modules/jquery/dist/jquery.js"></script>
<script src="../node_modules/bootstrap/dist/js/bootstrap.js"></script>
<script src="./assets/js/config/env.js"></script>

在您要使用jQuery ($)的.ts文件顶部,导入以下内容:

import $ from 'jquery';

现在,您可以将$用于jquery相关的事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM