最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Import jquery and bootstrap in typescript commonjs - Stack Overflow

programmeradmin5浏览0评论

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

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

i've tried some sintax like

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

or

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

but it's not working!

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

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

i've tried some sintax like

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

or

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

but it's not working!

Share Improve this question edited Aug 22, 2016 at 10:08 vitr 7,1348 gold badges32 silver badges52 bronze badges asked Aug 22, 2016 at 10:02 user1611404user1611404 761 gold badge2 silver badges5 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 11

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

This works for me:

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

import "bootstrap";

See this answer: Declare Typescript global variable as "module" type

at the start of your file you have to tell typescript it should know the typescript definitions of nodejs, jquery and so on.

/// <reference path="DEFINITION-FILE.d.ts" />

require is not known before the d.ts file nodejs isn't referenced $ or jquery is not known befor the d.ts file for jquery is not referenced ...

you can find a a large package of typescript definitions on Definitly Typed

http://definitelytyped/

i hope this is helpfull

Have you tried:

import * as $ from "jquery";

Make sure you have jQuery installed:

typings install jquery --save

import $ from "jquery"; is what works here.

发布评论

评论列表(0)

  1. 暂无评论