Skip to content

Instantly share code, notes, and snippets.

View pankajparkar's full-sized avatar
👨‍💻
Coding

Pankaj Parkar pankajparkar

👨‍💻
Coding
View GitHub Profile
@pankajparkar
pankajparkar / api.service.ts
Last active May 9, 2022 05:30
Storage Service implementation and consumptions
import { Injectable } from '@angular/core';
import { Entity } from '../enums';
import { FleetPosition, Player } from '../models';
import { StorageService } from './storage.service';
@Injectable({
providedIn: 'root'
})
export class ApiService {
import { AuthService } from './auth.service';
import { Injectable } from '@angular/core';
import {
HttpRequest, HttpHandler, HttpInterceptor, HttpSentEvent,
HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent
} from '@angular/common/http';
import { Observable, BehaviorSubject, throwError} from 'rxjs';
import { catchError, switchMap, finalize, filter, take, map } from 'rxjs/operators';
import { Router } from '@angular/router';
@pankajparkar
pankajparkar / token.interceptor.ts
Last active November 25, 2020 16:36
Final Token Interceptor
import { AuthService } from './auth.service';
import { Injectable } from '@angular/core';
import {
HttpRequest, HttpHandler, HttpInterceptor, HttpSentEvent,
HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent
} from '@angular/common/http';
import { Observable, BehaviorSubject, throwError} from 'rxjs';
import { catchError, switchMap, finalize, filter, take, map } from 'rxjs/operators';
import { Router } from '@angular/router';
@pankajparkar
pankajparkar / token.interceptor.ts
Last active May 4, 2020 11:40
token.interceptor.ts
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor
} from '@angular/common/http';
import { AuthService } from './auth/auth.service';
import { Observable } from 'rxjs';
// You can add URL which don't need AUTH header
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { TokenInterceptor } from './../auth/token.interceptor';
@NgModule({
bootstrap: [AppComponent],
imports: [...],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptorService,
multi: true
@pankajparkar
pankajparkar / token.interceptor.ts
Last active March 29, 2020 15:03
token.interceptor.ts
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor
} from '@angular/common/http';
import { AuthService } from './auth/auth.service';
import { Observable } from 'rxjs';
@pankajparkar
pankajparkar / app.service.ts
Last active March 8, 2020 15:40
Implement Authentication in Angular App
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';
@Injectable()
export class AppService {
constructor(private http: HttpClient) { }
getCountries() {
import { Component, OnInit, Input, Host } from '@angular/core';
import { TabsComponent } from '../tabs/tabs.component'
@Component({
selector: 'tab',
template: `
<div class="tab-pane" *ngIf="details.selected">
<h4>{{details.title}}</h4>
<ng-content></ng-content>
</div>
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'tabs',
template: `
<div class="tabbable">
<ul class="nav nav-tabs">
<li *ngFor="let pane of panes" [ngClass]="{active:pane.selected}">
<a href="#" (click)="select(pane)">
{{pane.title}}
.component('tabs', {
transclude: true,
controllerAs: 'tabs',
controller: [function TabsController() {
var tabs = this;
var panes = tabs.panes = []
tabs.select = function(pane) {
angular.forEach(panes, function(p) {
p.selected = false;
});