Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR TypeError: $(...).DataTable is not a function while using in angular 4

I'm getting ERROR TypeError: $(...).DataTable is not a function while using in angular 4.

enter image description here

Any suggestions for resolving this issue.

like image 709
Voolapati Manohar Avatar asked Jan 18 '26 05:01

Voolapati Manohar


2 Answers

If you are importing jQuery as a local lib, in your *component.ts file, like:

import * as jquery from 'jquery'

remove that line and treat it as a global library:

declare var jquery: any;

or

declare var $: any;

or just add one of that two lines to src/typings.d.ts

like image 138
Bogdan Avatar answered Jan 19 '26 19:01

Bogdan


Still I did not get datable(datatable is not a function) after adding

import * as $ from 'jquery';

Then I added below code also it's working now:

import 'datatables.net';

If you still did receive an error, try with the below also:

import 'datatables.net-bs4';
like image 45
Srinivasan N Avatar answered Jan 19 '26 20:01

Srinivasan N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!