Angular 如何从HttpClientInMemoryWebAPI模块中排除服务?
我已经在我的angular应用程序上配置了HttpClientInMemoryWebAPI模块。我想排除一个服务,这样我就可以测试它,而无需在第一个url中添加基本url: 问题: app.module.ts:Angular 如何从HttpClientInMemoryWebAPI模块中排除服务?,angular,httpclient,angular-services,angular-pipe,angular-in-memory-web-api,Angular,Httpclient,Angular Services,Angular Pipe,Angular In Memory Web Api,我已经在我的angular应用程序上配置了HttpClientInMemoryWebAPI模块。我想排除一个服务,这样我就可以测试它,而无需在第一个url中添加基本url: 问题: app.module.ts: imports: [ BrowserModule, HttpClientModule, HttpClientInMemoryWebApiModule.forRoot(InMemHeroService, { rootPath: '/api/'}) ], @
imports: [
BrowserModule,
HttpClientModule,
HttpClientInMemoryWebApiModule.forRoot(InMemHeroService, { rootPath: '/api/'})
],
@Injectable()
export class ServiceToExcludeService {
constructor(private http: HttpClient) { };
loadUsers(searchValue: string): Observable<Users> {
const url: string = 'http://localhost:4000/users?q=' + searchValue;
return this.http.get<Users>(url).pipe(
map(response => {
return (<Users>response)
}),
catchError(this.handleError));
}
serviceToExclude.service.ts:
imports: [
BrowserModule,
HttpClientModule,
HttpClientInMemoryWebApiModule.forRoot(InMemHeroService, { rootPath: '/api/'})
],
@Injectable()
export class ServiceToExcludeService {
constructor(private http: HttpClient) { };
loadUsers(searchValue: string): Observable<Users> {
const url: string = 'http://localhost:4000/users?q=' + searchValue;
return this.http.get<Users>(url).pipe(
map(response => {
return (<Users>response)
}),
catchError(this.handleError));
}
@Injectable()
将类服务导出到ExcludeService{
构造函数(私有http:HttpClient){};
loadUsers(searchValue:string):可观察{
常量url:string='1〕http://localhost:4000/users?q=“+搜索值;
返回此.http.get(url).pipe(
映射(响应=>{
返回(响应)
}),
catchError(this.handleError));
}
调用的链接是:
而不是:
那么我的问题是如何将此服务从以前的基本URL中排除?添加passThrUnknownUrl:
app.module.ts:
imports: [
BrowserModule,
HttpClientModule,
HttpClientInMemoryWebApiModule.forRoot(InMemHeroService, {
rootPath: '/api/',
passThruUnknownUrl: true
})
],
添加passThrUnknownUrl:
app.module.ts:
imports: [
BrowserModule,
HttpClientModule,
HttpClientInMemoryWebApiModule.forRoot(InMemHeroService, {
rootPath: '/api/',
passThruUnknownUrl: true
})
],