Firstly, install Toaster using Angular CLI.
The below code needs to be imported to the app.module.ts file.
The below code is used in component page level.
For the global settings to load a spinner at the service file level, if we define this below code in service level, we can call this method from component level.
With the use of Spinners, we can control the user action whenever a function works at runtime.
Step 1
Firstly, install ngx-spinner using Angular CLI and you can also check
here.
npm install ngx-spinner --save
Step 2
The below code is to Import NgxSpinnerModule in root module(AppModule) level.
-
- import { NgxSpinnerModule } from 'ngx-spinner';
- @NgModule({
- imports: [
-
- NgxSpinnerModule
- ]
- })
Step 3
Now, we need to use the NgxSpinnerService service wherever you want to use the ngx-spinner.
- import { NgxSpinnerService } from 'ngx-spinner';
- class AppComponent implements OnInit {
- constructor(private spinner: NgxSpinnerService) { }
-
- this.spinner.show();
-
- this.spinner.hide();
- }
Step 4
Now, we must configure the below code in our template app.componet.html file to maintain globally.
- <ngx-spinner bdOpacity=0.8 bdColor="rgba(51,51,51,0.8)" size="medium" color="#fff" type="ball-spin-clockwise" fullScreen="true">
- <p style="color: white"> Loading... </p>
- </ngx-spinner>
Here, you can also get different types of spinner animations at the following URL.
http://github.danielcardoso.net/load-awesome/animations.html
jQuery Data Table integration in Angular 7
Most of the developers know very well about jQuery Data Tables, but here, we can know how to integrate these to our Angular 7 project. So by using these, we can display the information in table format and we can apply data table features like navigation, sorting,..etc.
Step 1
Firstly, install the below jQuery DataTable dependencies using Angular CLI.
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
Step 2
Here, we need to add the below dependency scripts and styles in the angular.json file.
- {
- "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"],
- ...
- }
Step 3
The below code is to Import DataTablesModule in the root module(AppModule) level.
- import {
- DataTablesModule
- } from 'angular-datatables';
- @NgModule({
- declarations: [
- AppComponent
- ],
- imports: [
- BrowserModule,
- DataTablesModule
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule {}
Step 4
By the below code, we can understand how to consume and use jQuery Data Table in component page level.
- import {
- Subject
- } from 'rxjs';
- export class EmployeeListComponent implements OnInit {
- dtOptions: DataTables.Settings = {};
- empListData: Employee[];
-
-
- dtTrigger: Subject < any > = new Subject();
- ngOnInit(): void {
- this.loadDataTable();
- }
- loadDataTable(): void {
- this.dtOptions = {
- pagingType: 'full_numbers',
- pageLength: 2
- };
- this._http.get(this._usrSrv.getUrl('/Employee')).subscribe(res => {
- if (res != null) {
- this.ddlList = res as Employee[];
- this.empListData = res as Employee[];
- this.emSrv.list = res as Employee[];
-
- this.dtTrigger.next();
- }
- }, err => {});
- }
- }
Conclusion
I think the above 4 points are very useful in order to start & initiate a new web application using Angular 7 applications.