Sending HTTP Headers to every request in Angular
Let’s say we want to send 3 headers in http request : Content-Type, Accept and Accept-Language. To set headers for every request in Angular, we will create a class that implements HttpInterceptor.
HttpInterceptor
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest}
from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
@Injectable()
export class CustomHttpInterceptorService implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>
{
request = request.clone({
headers: request.headers.set('Content-Type', 'application/json')
});
if (!request.headers.has('Accept')) {
request = request.clone({
headers: request.headers.set('Accept', 'application/json')
});
}
request = request.clone({
...
Monday, 29 January 2018
PreLink, PostLink and Controller Methods of Angular Directives
PreLink, PostLink and Controller Methods of Angular Directives
Link function of an Angular Directive
As the name implicates, the link function has the duty of linking the model to the templates. Link function is the place where AngularJs does the data binding to the compiled templates. Let’s take a look at the signature of a link function.
link: function LinkFn(scope, elem, attr, ctrl){}
There...
Subscribe to:
Posts (Atom)
Topics
ADFS
(1)
ADO .Net
(1)
Ajax
(1)
Angular
(47)
Angular Js
(15)
ASP .Net
(14)
Authentication
(4)
Azure
(3)
Breeze.js
(1)
C#
(55)
CD
(1)
CI
(2)
CloudComputing
(2)
Coding
(10)
CQRS
(1)
CSS
(2)
Design_Pattern
(7)
DevOps
(4)
DI
(3)
Dotnet
(10)
DotnetCore
(20)
Entity Framework
(5)
ExpressJS
(4)
Html
(4)
IIS
(1)
Javascript
(17)
Jquery
(8)
jwtToken
(4)
Lamda
(3)
Linq
(10)
microservice
(4)
Mongodb
(1)
MVC
(46)
NodeJS
(8)
React
(10)
SDLC
(1)
Sql Server
(32)
SSIS
(3)
SSO
(1)
TypeScript
(3)
UI
(1)
UnitTest
(2)
WCF
(14)
Web Api
(16)
Web Service
(1)
XMl
(1)
Pages
- Dotnet Core Interview Q/A
- React JS Interview Questions and Answers
- Angular Interview Q/A
- Node JS Interview Q/A
- Azure Interview Q/A
- .Net Interview Q/A
- WEB API Interview Q/A
- Javascript Interview Q/A (Part- 1)
- Javascript Interview Q/A (Part- 2)
- SQLServer Interview Questions
- SQL - Query Related Interview Q/A
- ASP .Net MVC Interview Q/A
- Angular Testing Interview Q/A
- Lead level Interview Q/A
- WCF Interview Q/A
- ExpressJS Interview Q/A
- MongoDB Interview Q/A
- C# Programs Output Q/A
- InterView Programming
- ASP .Net Interview Q/A
- Angularjs Interview Q/A
- SQL Server 2005/2008 Functions
- Entity Framework Interview Q/A
- JQuery Selectors / Methods
- Ado .Net InterView Q/A
- LINQ Operators and Lambda Expression