使用jQuery内的角2应用globaly [英] using jQuery globaly within angular 2 application

查看:192
本文介绍了使用jQuery内的角2应用globaly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何在我的角2的应用程序,唯一合理的来源,我发现迄今为止全球范围内使用jQuery是这个 StackOverflow的答案不过,我似乎无法得到它的工作。有没有办法用 NPM 包管理,而不是TSD来实现这一(该命令不适合我的工作,我认为它是从打字稿来了,但好像没有)。

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

下面是我的项目结构

 应用
  组件
    app.ts
  服务
  分型
  bootstrap.ts
的index.html

和几个code的例子,我相信需要使用jQuery的执行

app.ts

 进口{组件,查看}从'angular2 /核心;@零件({
    选择:应用程序,
    templateUrl:应用程序/组件/ app.html
})出口类应用{}

bootstrap.ts

 进口{}应用程序从./components/app';引导(APP);


解决方案

下载的分型下的jQuery定义文件,并把这个在你的分型文件夹分型/ jQuery的/ jquery.d.ts

.TS 文件补充一点:

  ///<参考路径=分型/ jQuery的/ jquery.d.ts/>

包含在的jquery.js 文件的 index.html的

和..就是这样我猜:)

好运气

I'm trying to figure out how to use jQuery globally within my angular 2 app, 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).

After this I think I need to reference jQuery within my app.ts file? (main file used by bootstrap.ts to boot the application)

Here is my project structure

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

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);

解决方案

Download the typings definition file for jQuery, and place this in your typings folder under typings/jquery/jquery.d.ts.

Add this in your .ts file:

/// <reference path="typings/jquery/jquery.d.ts" />

Include the jQuery.js file in your index.html

And.. that's it I guess :)

Good luck

这篇关于使用jQuery内的角2应用globaly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆