When I started a web application using Angular 7 in the past, I faced a lot of problems, such as not being sure about the basic requirements. So, for this article, I have collected four simple requirements to start a web application using Angular 7.
- Bootstrap4 configuration in angular.json file
- Toaster Plugin integration.
- Spinner Integration.
- jQuery Data Tables Integration.
Bootstrap 4 Configuration in angular.json file globally in Angular 7
We all know about how Bootstrap is given a rich UI for making a simple design usage for developers but here, I have given small steps to configure this Bootstrap 4 globally in Angular 7.
Following are the steps to start the configuration.
Step 1
Firstly, install Bootstrap 4 using Angular CLI.
npm install bootstrap@4 jquery --save
Step 2
Now, we need to configure the angular.json file.
- "styles": [
- "src/styles.css",
- "node_modules/ngx-toastr/toastr.css",
- "node_modules/bootstrap/dist/css/bootstrap.min.css"
- ],
- "scripts": [
- "node_modules/jquery/dist/jquery.min.js",
- "node_modules/bootstrap/dist/js/bootstrap.min.js"
- ]
Based on the above configuration, we can directly consume the bootstrap class at component level.
Toaster integration in Angular 7
By using Toaster, we can display an error message "we are getting a problem in run time" and we can easily inform the user.
Step 1
Firstly, install Toaster using Angular CLI.
npm install ngx-toastr --save
Step 2
Now, we need to configure in the angular.json file.
- "styles": [
- "styles.scss",
- "node_modules/ngx-toastr/toastr.css" // try adding '../' if you're using angular cli before 6
- ]
Step 3
The below code needs to be imported to the app.module.ts file.
- import { ToastrModule } from 'ngx-toastr';
- imports: [
- CommonModule,
- BrowserAnimationsModule, // required animations module
- ToastrModule.forRoot({
- timeOut: 10000,
- closeButton:true,
- newestOnTop:true,
- positionClass: 'toast-bottom-center',
- preventDuplicates: true,
- }) // ToastrModule added
- ],
Step 4
The below code is used in component page level.
- import { ToastrService } from 'ngx-toastr';
- export class YourComponent {
- constructor(private toastr: ToastrService) {}
- showSuccess() {
- this.toastr.success('Hello world!', 'Toastr fun!');
- }
- }
Step 5
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.
- fireToasterMsg(msg: string, subMsg: string, msgType: string) {
- switch (msgType) {
- case 'success': { this._toaster.success(msg, subMsg); };
- case 'info': { this._toaster.info(msg, subMsg); };
- case 'error': { this._toaster.error(msg, subMsg) };
- case 'warning': { this._toaster.warning(msg, subMsg) };
- default: { this._toaster.info(msg, subMsg) };
- }
- }
Step 6 - Call the Toaster
this._usrSrv.fireToasterMsg('Internal Sever Error','Santosh Testing Demo','error');
Spinner for loading integration in Angular 7
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 library module
- 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) { }
- /** spinner starts on init */
- this.spinner.show();
- /** spinner ends */
- 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[];
- // We use this trigger because fetching the list of persons can be quite long,
- // thus we ensure the data is fetched before rendering
- 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[];
- // Calling the DT trigger to manually render the table
- 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.

anil badatiyaPosted Jul 10, 2019, 1:17 AM
Nice article..
Amit MohantyPosted Jul 7, 2019, 11:20 PM
Useful information.