api-prefix.interceptor.ts 可以正常工作,直到将“ GalleryModule”或“ LightboxModule”导入“ CampanhasModule”中。
我尝试过分别导入“ GalleryModule”或“ LightboxModule”,但是它们都不起作用。
这是导入模块之前的请求:
http://localhost:4200/api/campanhas?_page=1&_limit=1
这是导入模块后的请求:
http://localhost:4200/campanhas?_page=1&_limit=10
我的CampanhasModule.ts看起来像这样:
import { Commonmodule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FlexLayoutModule } from '@angular/flex-layout';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { MaterialModule } from '@app/material.module';
import { Sharedmodule } from '@app/shared';
import { NgBusyModule } from 'ng-busy';
import { NgxPaginationmodule } from 'ngx-pagination';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';
import { CampanhasRoutingModule } from './campanhas-routing.module';
import { CampanhasEditorComponent } from './editor/campanhas-editor.component';
import { CampanhasFiltroComponent } from './filtro/campanhas-filtro.component';
import { CampanhasListagemComponent } from './listagem/campanhas-listagem.component';
import { CampanhasApiService } from './service/campanhas-api.service';
import { LightboxModule } from '@ngx-gallery/lightbox';
import { GalleryModule } from '@ngx-gallery/core';
@NgModule({
imports: [
Commonmodule,FormsModule,Sharedmodule,FlexLayoutModule,MaterialModule,RouterModule,CampanhasRoutingModule,PerfectScrollbarModule,NgxPaginationmodule,NgBusyModule,LightboxModule,GalleryModule.withConfig({ loadingMode: 'indeterminate',loadingStrategy: 'preload' })
],declarations: [CampanhasListagemComponent,CampanhasEditorComponent,CampanhasFiltroComponent],providers: [CampanhasApiService]
})
export class CampanhasModule { }
我想知道为什么这些模块从我的请求中删除了“ / api”前缀。
有人有同样的问题吗?!
谢谢。
这是组件方法:
obterListagemCampanhas(pagina: number,dto?: FiltroListagemCampanhaDto) {
this.paginacao.currentPage = pagina;
this.busy$ = this.busy$.concat([
this.campanhasService.obterListagemCampanhas(pagina,dto).subscribe({
next: result => {
this.campanhas = result;
}
}),this.campanhasService.obterListagemCampanhasTotalItems(dto).subscribe({
next: result => {
this.paginacao.totalItems = result;
}
})
]);
}
这是“ campanhasService”中的方法:
obterListagemCampanhas(pagina: number,dto?: FiltroListagemCampanhaDto): Observable<CampanhaModel[]> {
let queryString = this.obterQueryStringFiltroListagemCampanhas(pagina,dto);
return this.httpClient.get(`${this.urlApiCampanhas}?${queryString}`).pipe(
tap({
error: error => {
this.snackService.abrirVermelho(
`Ocorreu um erro ao buscar as Campanhas,por favor,contate o administrador.`
);
}
}),delay(CONSTANTES.API.DELAY),map(response => response as CampanhaModel[])
);
}
obterListagemCampanhasTotalItems(dto?: FiltroListagemCampanhaDto): Observable<number> {
let queryString = this.obterQueryStringFiltroListagemCampanhas(1,dto);
let obs$ = Observable.create((observer: any) => {
this.httpClient
.get(`${this.urlApiCampanhas}?${queryString}`,{ observe: 'response' })
.pipe(
tap({
error: error => {
this.snackService.abrirVermelho(
`Ocorreu um erro ao buscar as agências,contate o administrador.`
);
}
}),take(1)
)
.subscribe({
next: (result: any) => {
observer.next(+result.headers.get('x-total-count'));
observer.complete();
},error: error => {
observer.error(error);
}
});
});
return obs$;
}