Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import jquery and bootstrap in typescript commonjs

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!

like image 374
user1611404 Avatar asked Aug 22 '16 10:08

user1611404


1 Answers

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

like image 154
c_froehlich Avatar answered Sep 22 '22 12:09

c_froehlich