3

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.

5
  • "Any suggestions for resolving this issue." Yes, include the DataTables library files. Commented Dec 3, 2017 at 14:20
  • Please share the steps, how to include DataTables library files Commented Dec 3, 2017 at 14:34
  • After adding libraries also. I'm getting the same issue. Commented Dec 3, 2017 at 16:01
  • I have literally no experience with Angular 2/4/5, but I would certainly first look at l-lin.github.io/angular-datatables/#/getting-started instead of trying to get the naked standalone jQuery version work. Commented Dec 3, 2017 at 16:23
  • Try solution given in below URL. stackoverflow.com/questions/32315701/… Commented Oct 25, 2018 at 4:48

3 Answers 3

9

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. declare var $: any; helped me with using jquery / datatables in Angular 6.
Thanks, @Bogdan I was searching this answer on data table site also but any solution over there was not helping your solution did help.
Thank you. declare var $: any; works with jquery / datatables in Angular 8.2.8.
1

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';

Comments

-1

En Laravel agregue "render" en los archivos importados.

Mi app.blade.php

<script src=" {{ asset('/assets/admin/plugins/jquery/jquery.min.js') }} "></script> 
<script src=" {{ asset('/assets/admin/plugins/bootstrap/js/bootstrap.bundle.min.js') }} "></script> 
<script src=" {{ asset('/assets/admin/dist/js/adminlte.min.js') }} "></script> 
@yield('scripts')

Y en mi archivo que importo donde esta mi tabla agrego el "defer"

@section('scripts')
    <!-- DataTables -->
    <script src=" {{ asset('/assets/admin/plugins/datatables/jquery.dataTables.min.js' ) }} " defer></script>
    <script src=" {{ asset('/assets/admin/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js') }} " defer></script>
    <script src=" {{ asset('/assets/admin/plugins/datatables-responsive/js/dataTables.responsive.min.js') }} " defer></script>
    <script src=" {{ asset('/assets/admin/plugins/datatables-responsive/js/responsive.bootstrap4.min.js') }} " defer></script>
    <script src=" {{ asset('/assets/admin/usuarios/listar_usuarios.js') }} "></script>
@endsection

2 Comments

Translate to english please :)
Please use english on SO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.