This project was generated with Angular CLI version 1.7.1.
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Run ng build
to build the project. The build artifacts will be stored in the dist/
directory. Use the -prod
flag for a production build.
Run ng test
to execute the unit tests via Karma.
Run ng e2e
to execute the end-to-end tests via Protractor.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.
Let’s install the Angular CLI with version 1.5.3.
npm install -g @angular/[email protected]
ng new angular5-datatable
Firstly, we need to install the dependencies required for DataTable. So, let’s do that for jQuery.
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 Secondly, we’ve to import the jQuery and DataTable JS/CSS in our app.
... "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" ], ...
Finally, we need to import the DataTableModule in our main module to make it available for all the components and allow them to start using DataTable: /src/app/app.module.ts
//Import DataTable import { DataTablesModule } from 'angular-datatables';
...
imports: [ BrowserModule, DataTablesModule ],