在Angular 2应用程序中全局使用jQuery [英] using jQuery globally within Angular 2 application
问题描述
我正试图弄清楚如何在我的角度2应用程序中全局使用jQuery,到目前为止我找到的唯一合理的来源是 stackoverflow答案然而,我似乎无法让它工作。有没有办法用 npm
包管理而不是tsd来实现这个目标(这个命令对我来说不起作用,我认为它来自于打字稿,但似乎没有)。
I'm trying to figure out how to use jQuery globally within my angular 2 app, the only reasonable source I found so far is this stackoverflow answer However I can't seem to get it working. Is there a way to achieve this with npm
package management instead of tsd (this command is not working for me, I assumed it is coming from typescript, but seems like not).
在此之后,我想我需要在app.ts文件中引用jQuery? (bootstrap.ts用来启动应用程序的主文件)
After this, I think I need to reference jQuery within my app.ts file? (main file used by bootstrap.ts to boot the application)
这是我的项目结构
app
components
app.ts
services
typings
bootstrap.ts
index.html
我认为需要用于jQuery实现的代码示例很少
and few code examples I believe need to be used for jQuery implementation
app.ts
import {Component, View} from 'angular2/core';
@Component({
selector: 'app',
templateUrl: 'app/components/app.html'
})
export class App { }
bootstrap.ts
import {App} from './components/app';
bootstrap(App);
推荐答案
使用以下命令安装jquery打字:
Install the jquery typings using:
npm install @types/jquery
在 index.html中包含
jQuery.js
文件
Include the jQuery.js
file in your index.html
而且......我想是的。)
And.. that's it I guess :)
祝你好运
这篇关于在Angular 2应用程序中全局使用jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!