Olá,
Estou tentando adicionar um interceptor no meu projeto angular 17 , conforme consta nas dependencias do meu projeto.
"dependencies": {
"@angular/animations": "^17.3.0",
"@angular/common": "^17.3.0",
"@angular/compiler": "^17.3.0",
"@angular/core": "^17.3.0",
"@angular/forms": "^17.3.0",
"@angular/platform-browser": "^17.3.0",
"@angular/platform-browser-dynamic": "^17.3.0",
"@angular/router": "^17.3.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.3.11",
"@angular/cli": "^17.3.11",
"@angular/compiler-cli": "^17.3.0",
"@types/jasmine": "~5.1.0",
"jasmine-core": "~5.1.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.4.2"
}
eu modifiquei o arquivo "main.ts" para que seja possível incluir um interceptador:
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { testeInterceptor } from './app/interceptor/teste/teste.interceptor';
import { provideHttpClient, withInterceptors } from '@angular/common/http';
bootstrapApplication(AppComponent, {
providers:[
provideHttpClient(
withInterceptors([testeInterceptor]),
)
]
})
.catch((err) => console.error(err));
e adicionei este interceptador funcional
import { HttpInterceptorFn } from '@angular/common/http';
export const testeInterceptor: HttpInterceptorFn = (req, next) => {
console.log('teste');
return next(req);
};
porém no console.log do navegador não aparece nada nem do terminal. Alguém poderia me ajudar?