javascriptjqueryangulartypescriptself-invoking-function

Angular2 Import self invoked jQuery library from query.selectareas.js give Runtime Error : jQuery is not defined


I have strange problem here with self invoked function which need jquery .

This is the library i want to use : jquery.selectareas.js

This is the code

import * as jQuery from 'jquery';
import  "query.selectareas.js"

Runtime Error : jQuery is not defined at this line

I tried to import JQ with all different combinations

//import * as $ from 'jquery';
//import * as jQuery from 'jquery';
//window['$'] = window['jQuery'] = $;
//import  "jquery"

What I understand that the imported jQuery should be available inside the jquery.selectareas.js scope when importing it, because they will be inside same scope .

Note : jquery work i used it after all import statements


Solution

  • You might need imports-loader

    import  "imports-loader?jQuery=jquery!query.selectareas.js"
    

    This will inject a jQuery variable to your imported module