Search code examples
javascriptjqueryaurelia

Using jQuery with Aurelia


I have an Aurelia app and in app.js I want to use jQuery.

So my config.js looks like:

System.config({
...
  map: {
    ...
    "jquery": "npm:[email protected]",
    ...
   }
}

And in app.js I import the jQuery like this:

var $ = require('jquery');

But when I require it, I get the blank site. Same it was with import:

import $ from 'jquery';

What is wrong?

Thanks

EDIT: ok, solved. The problem is, the jQuery code must be called inside the attached() mehtod. So like this:

export class Class1 {
    attached() {
        //jQuery code here
    }
}

Solution

  • You need to install jquery from https://github.com/components/jquery

    But if you use aurelia-skeleton, you can import it from bootstrap

    import 'bootstrap';
    

    and then use $ everywhere in app, or

    import $ from 'bootstrap'
    

    Same is for jqueryui. If needed get it from https://github.com/components/jqueryui