I am currently working with the visual studio 2017 template for my application. The visual studio 2017 project integrates Angular on the client side and ASP.NET Core MVC on the server side. I've run into an issue while trying to create an HTTP interceptor, specifically with TypeScript not being able to load the module. See the code snippet below:
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpInterceptor
} from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { AuthService } from './auth.service';
@Injectable()
export class TokenInterceptor implements HttpInterceptor {
constructor(public auth: AuthService) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
request = request.clone({
setHeaders: {
Authorization: `Bearer ${this.auth.getToken()}`
}
});
return next.handle(request);
}
}
I have already installed the necessary module via npm. Here's a glimpse of my package.json file:
{
"name": "MYAPP",
"private": true,
"version": "0.0.0",
"scripts": {
"test": "karma start ClientApp/test/karma.conf.js"
},
"dependencies": {
// List of dependencies
},
"devDependencies": {
// List of dev dependencies
}
}
Any idea why TypeScript is unable to locate the required module?
Thank you, B