What do you want to save?
Add Code snippet
New code examples
-
Javascript 2022-01-26 05:55:47
how to redirect from login page to other page if user is already logged in in angular using jwt
const ROUTES = [ { path: '', redirectTo: 'home', pathMatch: 'full' }, { path: 'login', component: LoginComponent }, { path: 'register', component: RegisterComponent }, { path: 'home', component: HomeComponent }, { path: 'books', component: BookC... Add solution -
Javascript 2022-01-23 03:21:01
warn user before leaving page angular
import { CanDeactivate } from '@angular/router'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; export interface ComponentCanDeactivate { canDeactivate: () => boolean | Observable<boolean>; } @Inject... Add solution -
Javascript 2021-11-17 14:59:20
subject in angular 8
import { Injectable } from '@angular/core'; import { Observable, Subject } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class MessageService { private subject = new Subject<any>(); sendMessage(message: string) { this.sub... Add solution -
Javascript 2021-11-15 09:26:54
angular http error handling
// src/app/services/interceptor.service.ts import { Injectable } from '@angular/core'; import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpErrorResponse } from '@angular/common/http'; import { Observable, throwEr... Add solution -
Javascript 2021-11-10 15:57:20
decode jwt token in angular
import { Injectable } from '@angular/core'; import * as jwt_decode from 'jwt-decode'; @Injectable() export class JWTTokenService { jwtToken: string; decodedToken: { [key: string]: string }; &nb... Add solution -
Javascript 2021-11-07 14:19:11
how to write test cases form behaviorsubject
import { Injectable } from '@angular/core';import { HttpClient } from '@angular/common/http';@Injectable({ providedIn: 'root'})export class UserService { public apiUrl = 'path/to/your/api'; constructor(private http: HttpClient) { } // Http request wit... Add solution -
Javascript 2021-11-06 11:15:10
interceptor in angular 8
// src/app/auth/auth.service.ts import { Injectable } from '@angular/core'; import decode from 'jwt-decode'; @Injectable() export class AuthService { public getToken(): string { return localStorage.getItem('token'); } public isAuthenticate... Add solution -
Javascript 2021-09-10 15:18:03
angular 12 service for create update delete local storage items
import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class LocalStorageService { localStorage: Storage; changes$ = new Subject(); constructor() { this.localStorage = window.lo... Add solution -
Javascript 2021-09-06 23:14:02
Angular 4 execute function from another component
//Angular 4 execute function from another component didn't get time to test it but similar solution worked for me. the code created for your need. Create a service like this import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/... Add solution -
Javascript 2021-09-04 09:01:03
jwt token local storage in angular
import { Injectable } from '@angular/core'; @Injectable() export class LocalStorageService { set(key: string, value: string) { localStorage.setItem(key, value); &n... Add solution
Best helpers
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5