gund / ng-http-interceptor

Http Interceptor library for Angular
MIT License
104 stars 16 forks source link

Installation Error #142

Closed yasiryc closed 7 years ago

yasiryc commented 7 years ago

I install the latest version from NPM and getting following error on ng serve

Angular version - 4.0.1 Typescripit - 2.2.1

ERROR in ./~/ng-http-interceptor/dist/http/interceptable-http.js Module not found: Error: Can't resolve 'tslib' in 'C:\source\Angular\client\node_modules\ng-http-interceptor\dist\http' @ ./~/ng-http-interceptor/dist/http/interceptable-http.js 1:0-33 @ ./~/ng-http-interceptor/dist/http/index.js @ ./~/ng-http-interceptor/dist/index.js @ ./src/app/app.module.ts @ ./src/main.ts @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

gund commented 7 years ago

Please install npm module tslib and add to your tsconfig file importHelpers: true

yasiryc commented 7 years ago

Thanks for the feedback. I initially thought i had tslib installed which i did but was missing tsconfig setting.

I have created the interceptor as seperate service and register it to app module but not able to intercept any requests.

Any ideas what i might be missing here..

gund commented 7 years ago

Did you import the module itself into the root module?

yasiryc commented 7 years ago

Yes i did. I imported module from ng-http-interceptor

import { HttpInterceptorModule } from 'ng-http-interceptor';

Also i registered custom interceptor service as provider in the root module. Here is code from custom interceptor service

`import { Injectable } from '@angular/core'; import { HttpInterceptorService } from 'ng-http-interceptor';

@Injectable() export class HttpcustominterceptorService {

constructor(private _httpInterceptor: HttpInterceptorService) { _httpInterceptor.request().addInterceptor((data, method) => { console.log("Inside Interceptor Request"); console.log(method, data); return data; });

_httpInterceptor.response().addInterceptor((res, method) => {
  console.log("Inside Interceptor response");
  return res.do(r => console.log(method, r));
});

}

}

gund commented 7 years ago

That looks right and should work fine. Can you create a plunkr with your problem so I can verify it?

gund commented 7 years ago

Will close this one since too long. If you still have an issue - feel free to reopen.