在 Angular 2 应用程序中全局使用 jQuery

using jQuery globally within Angular 2 application

本文关键字:jQuery 全局 Angular 应用程序      更新时间:2023-09-26

我正在尝试弄清楚如何在我的 angular 2 应用程序中全局使用 jQuery,到目前为止我找到的唯一合理来源是这个堆栈溢出答案但是我似乎无法让它工作。有没有办法通过npm包管理而不是 tsd 来实现这一点(这个命令对我不起作用,我假设它来自打字稿,但似乎不是)。

在此之后,我想我需要在我的app.ts文件中引用jQuery?(bootstrap.ts 用于启动应用程序的主文件)

这是我的项目结构

app
  components
    app.ts
  services
  typings
  bootstrap.ts
index.html

以及我认为需要用于jQuery实现的几个代码示例

应用程序

import {Component, View} from 'angular2/core';
@Component({
    selector: 'app',
    templateUrl: 'app/components/app.html'
})
export class App { }

引导程序.ts

import {App}              from './components/app';
bootstrap(App);

使用以下方法安装 jquery 类型:

npm install @types/jquery

index.html中包含jQuery.js文件

而且..我想就是这样:)

祝你好运