在typescript commonjs中导入jquery和bootstrap [英] Import jquery and bootstrap in typescript commonjs

查看:205
本文介绍了在typescript commonjs中导入jquery和bootstrap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用browserify导入一些nodejs模块。所有工作正常使用这个sintax:

i'm using browserify to import some nodejs modules. All working fine using this sintax:

$ = jQuery = require('jquery');
require('bootstrap');
require('angular');
require('ngRoute');
require('firebase');
require('angularfire');

现在我正在尝试将其转换为打字稿(使用版本1.8),但我无法想象怎么做。我正在使用来自browserify的tsify插件

Now i'm trying to convert that in typescript (using version 1.8) but i can't figure how to do it. I'm using tsify plugin from browserify

我尝试了一些sintax,如

i've tried some sintax like

import * as jquery from "jquery";
import * as jQuery from "jquery";
import * as $ from "jquery";

declare var jQuery;
declare var $;
import * as jquery from "jquery";
$ = jQuery =jquery;

但它不起作用!

推荐答案

要在浏览器中全局使用jQuery,需要将其附加到windows对象。

To have 'jQuery' available globally in the browser you need to attach it to the windows object.

这对我有用:

import * as $ from "jquery";
(<any>window).jQuery = $

import "bootstrap";

看到这个答案:将Typescript全局变量声明为" module"输入

这篇关于在typescript commonjs中导入jquery和bootstrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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