5

I am not able to include DataTableModule into our Angular 6 project with datatable. I am using angular cli 6 with datatable. My code is showing error that cannot find module DataTablesModule. I have installed all packages related to datatable and jquery. It is also displaying into node_modules folder but not able to add into app.module.ts.

I am attaching the screenshot below:

Here is my code.

Here is my code

Getting this error in browser

enter image description here

2
  • have you included the file path in the angular.json? Commented Oct 12, 2018 at 11:08
  • yes I have included Commented Oct 12, 2018 at 12:00

3 Answers 3

6

Maybe you are missing any dependency. Follow the steps given in this documentation Angular Datatables

1: Install all the dependencies

  • npm install jquery --save
  • npm install datatables.net --save
  • npm install datatables.net-dt --save
  • npm install angular-datatables --save
  • npm install @types/jquery --save-dev
  • npm install @types/datatables.net --save-dev

2: Add all the dependencies in angular.json

{
  "projects": {
    "your-app-name": {
      "architect": {
        "build": {
          "options": {
            "styles": [
              "node_modules/datatables.net-dt/css/jquery.dataTables.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/datatables.net/js/jquery.dataTables.js"
            ],
            ...
}

3: Import in app-module

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { DataTablesModule } from 'angular-datatables';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,

    DataTablesModule
  ],
  providers: [],
  bootstrap: [ AppComponent ]
})
export class AppModule {}
Sign up to request clarification or add additional context in comments.

2 Comments

followed all these steps, but still angular datatable is showing error
Thank you very much! This is working perfectly for me and I already used it in plenty projects.
0

I had the same problem. I solved it by running the following command in terminal:

ng add angular-datatables

Ref: https://www.npmjs.com/package/angular-datatables/v/9.0.2

Also, This is my complete code if someone want to take a look.

https://github.com/xbox2204/SpringBoot-JPA-Swagger-Angular

Comments

0

I had the same error because i used the angular CLI command: ng add angular-datatables. but when i installed the packages manually, the error was gone. this is the packages :

npm install jquery --save
npm install datatables.net --save
npm install datatables.net-dt --save
npm install angular-datatables --save
npm install @types/jquery --save-dev
npm install @types/datatables.net --save-dev

Comments

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.