我想知道使用哪一个来构建模拟Web服务来测试Angular程序?
我正在使用CLI启动一个新的角度项目,并且我遇到了HttpClient
错误的无提供程序.
我已经添加HttpClientModule
到我的模块导入,这似乎是这种情况下的常见罪魁祸首.除此之外没有找到很多在线,所以我不确定问题是什么.
我的app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
和我的服务
@Injectable()
export class FlexSearchService {
constructor(private http: HttpClient) {}
getSavedSearchResult(index: string, queryName: string, query: string ): Observable<any> {
const url = `${environment.flexUrl}/${index}/search`;
const item = new SearchQuery({queryName: queryName, variables: {q: query}});
return this.http.post(url, item);
}
}
Run Code Online (Sandbox Code Playgroud)
和ng版本提供以下输出
@angular/cli: 1.4.2
node: 6.9.4
os: darwin x64
@angular/animations: 4.4.4
@angular/common: 4.4.4
@angular/compiler: 4.4.4
@angular/core: 4.4.4 …
Run Code Online (Sandbox Code Playgroud)