Add AuthInterceptor that will intercept all your HTTP requests and add the token to its headers: import { Injectable } from ‘@angular/core’; import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from ‘@angular/common/http’; import { Observable } from ‘rxjs’; @Injectable() export class AuthInterceptor implements HttpInterceptor { intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const token = localStorage.token; // […]
Multi-casting is the practice of broadcasting to a list of multiple subscribers in a single execution. Let’s demonstrate the multi-casting feature, var source = Rx.Observable.from([1, 2, 3]); var subject = new Rx.Subject(); var multicasted = source.multicast(subject); // These are, under the hood, `subject.subscribe({…})`: multicasted.subscribe({ next: (v) => console.log(‘observerA: ‘ + v) }); multicasted.subscribe({ next: (v) […]
How can I set the header in every request in angular? Let’s say I have token in localStorage and that needs to set for every REST API call.
How to use multicast of Rxjs in angular? It will be great if you can explain with an example.
What is AsyncPipe in angular and how to use it? It will be great if someone can explain with an example.
If the URL doesn’t match any predefined routes then it causes the router to throw an error and crash the app. In this case, you can use a wildcard route. A wildcard route has a path consisting of two asterisks to match every URL. For example, you can define PageNotFoundComponent for wildcard route as below: […]
How to define wildcard route in angular? I have to show page not found component if the URL doesn’t match anything.
I believe you need to use [routerLinkActiveOptions] in your template page. [routerLinkActiveOptions]=”{exact:true}” Set the above [routerLinkActiveOptions] directive to all navigation links, which will add the routerLinkActive class to only those navigation links which match the entire URL.
I am using the angular 10 version I have an issue withΒ the routerLinkActive it is setting the home URL (base URL) to active even if the route is on another page. <li class=”nav-item”> <a class=”nav-link” [routerLink]='[“”]’ routerLinkActive=’active’>Home</a> </li> <li class=”nav-item”> <a class=”nav-link” [routerLink]='[“/contact-us”]’ routerLinkActive=’active’>Contact Us</a> </li>
Annotations In Angular, annotations are used for creating an annotation array. They are only metadata sets of the class using the Reflect Metadata library. Decorators In Angular Decorators are design patterns used for separating decoration or modification of some class without changing the source code.