akveo / akveo/ngx-admin

HTTP_INTERCEPTOR not called from new module

Ouverte
#5,495 0 commentaires 1 réaction 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
25.7k
Forks
7.9k
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

### Issue type

**I'm submitting a ...** (check one with "x")

* [x] bug report
* [ ] feature request
* [ ] question about the decisions made in the repository

### Issue description
HTTP_INTERCEPTOR is not called from any page under 'pages' module.

**Current behavior:**
I've created a new module called 'listados.module' under 'pages' with it's own routing and components.

I've also using NbAuthJWTInterceptor for injecting Bearer (but any interceptor will do, I also created an interceptor with tracing just to be sure)

When calling HttpClient from any component under 'listados', the interceptor is not called. Login /logout calls, however are correctly intercepted. Only thing I can figure out is about the way that NbAuthModule is loaded, which not happens with any page module (which is lazy loaded)

**Expected behavior:**
Any HTTP_INTERCEPTOR registered on app.module should work from any page, the same way it works when called from login /logout pages.

**Steps to reproduce:**
- Register NbAuthJWTInterceptor in app.module (any interceptor will do, I've also created an empty interceptor and it's not called either)
- Take any existing component (I choose ngx-kitten)
- Modify the component so it implements OnInit
- Inject HttpClient in the component
- Make any http operation using the injected HttpClient. In example, http.get() in ngOnInit() method
- Make the result available in the view kitten.component.html (either if the result is ok or if you got an error)
- Check the iot-dashboard for the results.

**Related code:**

```
import { Component, OnInit, OnDestroy } from '@angular/core';
import { NbThemeService } from '@nebular/theme';
import { HttpClient } from '@angular/common/http';

@Component({
selector: 'ngx-kitten',
styleUrls: ['./kitten.component.scss'],
templateUrl: './kitten.component.html',
})
export class KittenComponent implements OnInit, OnDestroy {

currentTheme: string;
themeSubscription: any;
httpSubscription: any;
serviceResults: string = 'Hi, you!';

constructor(private themeService: NbThemeService, private http: HttpClient) {
this.themeSubscription = this.themeService.getJsTheme().subscribe(theme => {
this.currentTheme = theme.name;
});
}

ngOnInit() {
this.httpSubscription = this.http.get('http://localhost:5000/api/auth/users').subscribe(
res => {
this.serviceResults = JSON.stringify(res);
},
err => {
this.serviceResults = JSON.stringify(err);
});
}

ngOnDestroy() {
this.themeSubscription.unsubscribe();
}
}

```

### Other information:

**npm, node, OS, Browser**
```
node version: v10.16.0
npm version: 6.10.3
Windows 10
Browser: Chrome /Edge Chromium
```

**Angular, Nebular**
```
Nebular: 4.1.2
Angular: 8.0.2
```

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.