I have a requirement How to create a spinner common component with a spinner service(costume service) file for angular 5. that once I click on button and drop down also , sp
Change _loaderShow true false where you want to show or hide loader
in html file
<div class="loading" *ngIf="_loaderShow">Loading</div>
in component file
_loaderShow = true;
Css
.loading {
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: show;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
/* Transparent Overlay */
.loading:before {
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.3);
}
/* :not(:required) hides these rules from IE9 and below */
.loading:not(:required) {
/* hide "loading..." text */
font: 0/0 a;
color: transparent;
text-shadow: none;
background-color: transparent;
border: 0;
}
.loading:not(:required):after {
content: '';
display: block;
font-size: 10px;
width: 1em;
height: 1em;
margin-top: -0.5em;
-webkit-animation: spinner 1500ms infinite linear;
-moz-animation: spinner 1500ms infinite linear;
-ms-animation: spinner 1500ms infinite linear;
-o-animation: spinner 1500ms infinite linear;
animation: spinner 1500ms infinite linear;
border-radius: 0.5em;
-webkit-box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.5) -1.5em 0 0 0, rgba(0, 0, 0, 0.5) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) -1.5em 0 0 0, rgba(0, 0, 0, 0.75) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
}
This is kind of an easy and ready made solution. Download font awesome CSS icon pack from here:
https://fontawesome.com/v4.7.0/get-started
Then include the 'font-awesome.min.css' file from the css folder within the head tags of your "index.html":
<link rel="stylesheet" href="font-awesome.min.css"/>
Create a spinner component that you can resize and reuse everywhere:
spinner.component.ts:
import { Component, Input } from '@angular/core';
@Component
({
selector : 'spinner',
templateUrl : './spinner.component.html'
})
export class spinnerComponent
{
@Input () spinnerSize;
}
spinner.component.html:
<div *ngIf = "spinnerSize == 1">
<i class="fa fa-spinner fa-spin fa-1x"></i>
</div>
<div *ngIf = "spinnerSize == 2">
<i class="fa fa-spinner fa-spin fa-2x"></i>
</div>
<div *ngIf = "spinnerSize == 3">
<i class="fa fa-spinner fa-spin fa-3x"></i>
</div>
In any template where you would wish to use the spinner just include the following:
<spinner [spinnerSize] = 1 ></spinner>