3

I am trying to open bootstrap modal but its not working in fullcalendar angular 2.

dayClick: function(date, jsEvent, view) {
        (<any>$('#myModal33')).modal('show');
        $('#click_date').val(date._d);
      }

I get:

WEBPACK_IMPORTED_MODULE_5_jquery(...).modal is not a function

If I remove this import * as $ from 'jquery'; then the modal is working, but I need jQuery as well.

ADyson
  • 57,178
  • 14
  • 51
  • 63
Jay Patel
  • 305
  • 2
  • 6
  • 20

3 Answers3

14

just change:

import * as $ from 'jquery';

as:

import * as $AB from 'jquery';

this solved my problem. now its work like vroom vroom.... yeheeeee.....

Jay Patel
  • 305
  • 2
  • 6
  • 20
3

I think this question has been answered. Managing jQuery plugin dependency in webpack.

Use the ProvidePlugin to inject implicit globals

Most legacy modules rely on the presence of specific globals, like jQuery plugins do on $ or jQuery. In this scenario you can configure webpack, to prepend var $ = require("jquery") everytime it encounters the global $ identifier.

custom.typings.d.ts might be needed to prevent typescript errors.

You could install "@types/jquery" and this file might not be needed.

declare var $: any;

webpack.config.js

var webpack = require("webpack");

...

plugins: [
    new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery"
    })
]
Community
  • 1
  • 1
LT56
  • 187
  • 6
2

The accepted answer does work but here's my thought why the $AB works, but not the $.

From the @types/jquery page, it says that the package contains global values $, Symbol and jQuery. In this case, you need to import everything from the package but not overriding the three variables themselves.

So, just add the below line into your app.module.ts and you will be able to use the $ mark throughout your application.

import * as AnythingThatIsNotDollarSignOrSymbolOrjQuery from "jquery"
Fangming
  • 24,551
  • 6
  • 100
  • 90