Skip to content

Instantly share code, notes, and snippets.

@codewithsrini
Created July 16, 2020 13:32
Show Gist options
  • Save codewithsrini/2aae47073072b12cd21484aae47b61f9 to your computer and use it in GitHub Desktop.
Save codewithsrini/2aae47073072b12cd21484aae47b61f9 to your computer and use it in GitHub Desktop.
<div class="page-overlay-wrapper" *ngIf="showSpinner">
<div class="bee-spinner"></div>
</div>
@keyframes bouncing {
0% {
top: 40%;
}
100% {
top: 30%;
}
}
@keyframes fadein {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.page-overlay-wrapper {
position: fixed;
width: 100%;
height: 100%;
top: 0;
z-index: 1009;
background: rgba(112, 191, 93, 0.5);
.bee-spinner {
width: 20%;
height: 20%;
position: fixed;
top: 40%;
left: calc(50% - 10%);
z-index: 100;
background-image: url(../../assets/bee-spinner.png);
background-repeat: no-repeat;
background-size: 97%;
animation: bouncing 0.4s cubic-bezier(0.1, 0.25, 0.1, 1) 0s infinite
alternate both;
}
}
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { SpinnerService } from './spinner.service';
@Component({
selector: 'app-spinner',
templateUrl: './spinner.component.html',
styleUrls: ['./spinner.component.scss']
})
export class SpinnerComponent implements OnInit {
showSpinner = false;
constructor(private spinnerService: SpinnerService, private cdRef: ChangeDetectorRef) {
}
ngOnInit() {
this.init();
}
init() {
this.spinnerService.getSpinnerObserver().subscribe((status) => {
this.showSpinner = (status === 'start');
this.cdRef.detectChanges();
});
}
}
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class SpinnerService {
private count = 0;
private spinner$ = new BehaviorSubject<string>('');
constructor() { }
getSpinnerObserver(): Observable<string> {
return this.spinner$.asObservable();
}
requestStarted() {
if (++this.count === 1) {
this.spinner$.next('start');
}
}
requestEnded() {
if (this.count === 0 || --this.count === 0) {
this.spinner$.next('stop');
}
}
resetSpinner() {
this.count = 0;
this.spinner$.next('stop');
}
}
@Jocatins
Copy link

Jocatins commented Jan 6, 2021

Hello, Please I do not understand what you did in your interceptor file. Can you help me with the codes for better clarifications.

@Mahendra0506
Copy link

Can I get the code for http-error. Interceptor and index.ts.. Please

@Charmi-2017
Copy link

For interceptor code, you can go through the youtube video
Link - https://www.youtube.com/watch?v=H9KLIbisVJ8&t=909s

@tusharjain88954
Copy link

please! provide http interceptor code also, its hard to read it and write it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment