Skip to content

Instantly share code, notes, and snippets.

A new opportunity ? hmmm why not

William Koza wKoza

A new opportunity ? hmmm why not
View GitHub Profile
View drop.html
<div class="my-drop-zone" ngxDragAndDrop>
Drop files here to upload
View AppModule.ts
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {HttpClientModule} from '@angular/common/http';
import {NgxUploadModule} from '@wkoza/ngx-upload';
imports: [
View upload.component.html
<div class="col-md-9" style="margin-bottom: 40px">
<h3>Upload queue <span *ngIf="uploader.queue.length>0"> - {{ uploader.queue.length }} item(s)</span></h3>
<div class="card text-right">
<div style="margin: 15px">
<ngb-progressbar showValue="true" type="success" [striped]="true" [animated]="true"
<div class="card-block">
<button type="button" class="btn btn-outline-success btn-s" (click)="uploader.uploadAll({method: 'POST', url: 'my_url'})"
View use.httpclient.ts
export const HTTP_INTERCEPTORS_1 = new InjectionToken<HttpInterceptor[]>('HTTP_INTERCEPTORS_1');
export const HTTP_INTERCEPTORS_2 = new InjectionToken<HttpInterceptor[]>('HTTP_INTERCEPTORS_2');
export class Http1Service extends HttpClient {
constructor(backend: HttpBackend, private injector: Injector) {
super(new MyHandlerService(backend, injector, HTTP_INTERCEPTORS_1));
View rewrite.handler.ts
import {InjectionToken, Injector} from '@angular/core';
import {HttpBackend, HttpEvent, HttpInterceptor, HttpReques, HttpHandler, HttpRequest} from '@angular/common/http';
import { Observable } from 'rxjs';
* `HttpHandler` which applies an `HttpInterceptor` to an `HttpRequest`.
export class MyHttpInterceptorHandler implements HttpHandler {
constructor(private next: HttpHandler, private interceptor: HttpInterceptor) {}
View angular.httpclient.ts
export class HttpInterceptingHandler implements HttpHandler {
private chain: HttpHandler|null = null;
constructor(private backend: HttpBackend, private injector: Injector) {}
handle(req: HttpRequest<any>): Observable<HttpEvent<any>> {
if (this.chain === null) {
const interceptors = this.injector.get(HTTP_INTERCEPTORS, []);
this.chain = interceptors.reduceRight(
View simple.httpClient.ts
export class Http1Service extends HttpClient { };
export class Http2Service extends HttpClient { };
providers: [
{provide: Http1Service, useClass: HttpClient},
{provide: Http2Service, useClass: HttpClient},
View httpClient2.ts
Observable<Article> article$ = this.http.get<Article>('', {responseType: 'blob'});
View httpClient1.ts
Observable<Article[]> articles$ = this.http.get<Article[]>('');
wKoza / httpclient.ts
Last active Jul 17, 2017
View httpclient.ts
Observable<Article[]> articles$ = this.http.get('')
.map((res:Response) => res.json() as Article[]);