Skip to content

Instantly share code, notes, and snippets.

View keithstric's full-sized avatar

Keith Strickland keithstric

  • Douglasville, GA
  • 17:26 (UTC -04:00)
View GitHub Profile
// Show a very simple dialog
const textModalConfig = {
modalTitle: 'A reusable modal dialog',
modalTextContent: 'Here is the body of the dialog',
data: {foo: 'bar'},
confirmButtonLabel: 'Roger that!',
confirmHandler: (data) => {
console.log('Modal confirm handler', data);
},
cancelHandler: () => {
import {Injectable} from '@angular/core';
import {ServiceLocator} from '@core/services/service-locator';
import {ConfirmModalComponent} from '@shared/components/confirm-modal/confirm-modal.component';
import { ConfirmModalConfig } from '@shared/components/confirm-modal/confirm-modal.interface';
import {BsModalService, ModalOptions} from 'ngx-bootstrap/modal';
/**
* This service should only contain static methods for showing notifications to the user
*/
@Injectable()
import {Component, Injector, TemplateRef} from '@angular/core';
import {FormGroup} from '@angular/forms';
import {BsModalRef, ModalOptions} from 'ngx-bootstrap/modal';
@Component({
selector: 'app-confirm-modal',
templateUrl: './confirm-modal.component.html',
styleUrls: ['./confirm-modal.component.scss']
})
export class ConfirmModalComponent {
<div class="modal-header flex-row">
<div class="modal-header-text">
{{modalHeaderText}}
</div>
<button class="btn btn-link" (click)="bsModalRef.hide()">
<i class="fas fa-times"></i>
</button>
</div>
<div class="modal-body">
<h2 *ngIf="modalTitle" class="modalTitle">{{modalTitle}}</h2>
import {Component, TemplateRef} from '@angular/core';
import {FormGroup} from '@angular/forms';
import {ModalOptions} from 'ngx-bootstrap/modal';
export interface ConfirmModalConfig {
/**
* The text which will show in the modal-header
*/
modalHeaderText?: string;
/**
import {Injectable} from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpResponse, HttpErrorResponse
} from '@angular/common/http';
import {HttpCacheService} from '@core/services/http-cache/http-cache.service';
import {Logger} from '@core/services/logger/logger';
import {Observable, of} from 'rxjs';
import {HttpRequest, HttpResponse} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {CachableRoutePatterns} from '@core/interfaces/api.interface';
import {LocalStorageTypes} from '@core/interfaces/local-storage.interface';
import {LocalStorageService} from '@core/services/local-storage/local-storage.service';
import {Logger} from '@core/services/logger/logger';
import * as Route from 'route-parser';
abstract class HttpCache {
abstract get(req: HttpRequest<any>): HttpResponse<any> | null;
@keithstric
keithstric / api.interface.ts
Last active June 25, 2021 13:42
http-cache
export const CachableRoutePatterns = {
'/api/person/:id': true,
'https://pokeapi.co/api/v2/pokemon': false
};
// This will NOT go through our error handler
try {
(null as any).f();
} catch (e) {
console.error(e);
}
// This will go through our error handler
try {
(null as any).f();
@NgModule({
imports: [
CommonModule,
HttpClientModule,
MaterialModule
],
providers: [
{provide: ErrorHandler, useClass: ErrorService}
]
})