角度http请求不起作用,但在邮递员上工作

时间:2018-12-29 16:04:28

标签: javascript angular typescript http angular-http

我正在尝试使用以下网址发出http get请求:

ERROR in C:/Users/admin/Documents/material2/dist/releases/cdk/esm5/drag-drop.es5.js
Module not found: Error: Can't resolve '@angular/cdk/bidi' in 'C:\Users\admin\Documents\material2\dist\releases\cdk\esm5'
ERROR in C:/Users/admin/Documents/material2/dist/releases/cdk/esm5/drag-drop.es5.js
Module not found: Error: Can't resolve '@angular/cdk/coercion' in 'C:\Users\admin\Documents\material2\dist\releases\cdk\esm5'
ERROR in C:/Users/admin/Documents/material2/dist/releases/cdk/esm5/drag-drop.es5.js
Module not found: Error: Can't resolve '@angular/cdk/platform' in 'C:\Users\admin\Documents\material2\dist\releases\cdk\esm5'
ERROR in C:/Users/admin/Documents/material2/dist/releases/cdk/esm5/drag-drop.es5.js
Module not found: Error: Can't resolve '@angular/cdk/scrolling' in 'C:\Users\admin\Documents\material2\dist\releases\cdk\esm5'

但是什么也没发生。如果我在浏览器中打开网络部分,则没有请求记录。如果我在邮递员中使用相同的URL,它将正确执行请求。

2 个答案:

答案 0 :(得分:2)

缺少对可观察对象的订阅。如果不对可观察的对象调用subscribe,则基础链将不执行任何操作。

答案 1 :(得分:1)

您似乎从未订阅过get请求。订阅后便会触发该请求。

return this.http.get<any>(url,httpOptions).pipe(
  tap(_ => this.log(`updated material price id=${id}`)),
  catchError(this.handleError<any>('updateMaterialPrice'))
).subscribe((result) => {
  console.log('now it should work', result);
})

请参见https://angular.io/api/common/http/HttpClient#get