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 badges4 Answers
Reset to default 11To 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.