angular2 services - Angular 4.2.x interceptor is not being executed -


i using
- angular 4.2.4

i trying intercept service using below angular code

import {injectable} '@angular/core'; import {httpevent, httpinterceptor, httphandler, httprequest}  '@angular/common/http'; import { observable } 'rxjs/rx'; export class localhttpclientinterceptor implements httpinterceptor { intercept(req: httprequest<any>, next: httphandler):  observable<httpevent<any>> {   const username = 'me';   const password = 'blahblah';   const authreq = req.clone({headers: req.headers.set('authorization',  'basic ' + btoa(username + ':' + password))});   return next.handle(authreq);   }  } 

in module file

import { localhttpclientinterceptor } './local-http-client- interceptor';   @ngmodule({    imports: [    commonmodule,    formsmodule,    reactiveformsmodule,    mdautocompletemodule,    mdinputmodule,    mdiconmodule,    httpmodule,    mdgridlistmodule,    flexlayoutmodule  ],  declarations: [ usersearchcomponent, objectcomponent],  exports: [usersearchcomponent, objectcomponent, flexlayoutmodule],  providers : [{  provide: http_interceptors,  useclass: localhttpclientinterceptor,  multi: true,  }, usersearchservice, localhttpclientservice, storageservice] })  export class sharedmodule { } 

problem : able see debug point @ intercept function definition triggered, after doing service call code inside intercept not being called.

i using angular http @angular/http call service using get,options,post methods

according official change logs package @angular/common/http available angular 4.3.0 , using 4.2.4 think might reason. , try use @angular/common/http instead of @angular/http.

for how use new httpclient in angular https://angular.io/guide/http

here working plunker https://plnkr.co/edit/wtl8eiacpov6scwbfpwx?p=preview

for more change logs visit https://github.com/angular/angular/blob/master/changelog.md


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -