Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何从HttpClientInMemoryWebAPI模块中排除服务?_Angular_Httpclient_Angular Services_Angular Pipe_Angular In Memory Web Api - Fatal编程技术网

Angular 如何从HttpClientInMemoryWebAPI模块中排除服务?

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/'}) ], @

我已经在我的angular应用程序上配置了HttpClientInMemoryWebAPI模块。我想排除一个服务,这样我就可以测试它,而无需在第一个url中添加基本url: 问题:

app.module.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));
}
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
    })
],