angular - 使用 Angular 6,为什么 http.get() 不检索我的静态数据?
问题描述
我在使用 SSL 和 CORS 包运行的 Linux 上安装了 Node.js 服务器。我可以在 Firefox 中使用 HTTPS 协议从 Windows 访问我的网站:
https://<host-name>:<port>/
但是,在我的 Angular 代码中,使用:
http.get("https://<host-name>:<port>/test/data")
我只收到此错误消息*Array.from is not a function*.
在查看开发人员工具屏幕时,我实际上并没有看到浏览器进行 HTTPS 调用。
如果我运行服务器并使用本地浏览器,一切正常!
这可能是 polyfills 问题、另一个 CORS 问题还是其他问题?
这是我的服务的一部分:
...
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, of } from 'rxjs';
...
export class ObtainData
{
private val: any;
private obsvbl: Observable<any>;
private url = 'https://<host-name>:<port>/test/data';
constructor(private http: HttpClient);
getData(): Observable<any>
{
this.obsvbl = this.http.get<any>(this.url);
this.obsvbl.subscribe((data: any) =>
{
console.log("data is: " + data.val);
// 'val' is a string contained in
// a JSON structure.
this.val = data;
},
err => console.log("Err is: " + err.message),
() => console.log("Done!"));
return this.obsvbl;
}
}
我用这个命令构建:
ng build --aot --base-href=/testing-area/
我无法剪切/粘贴整个堆栈跟踪,但我会在这里尽可能多地输入:
"Err is: Array.from is not a function" (main.js:290)
"ERROR" TypeError: a[getSymbolIterator(...)] is not a function (main.js:393)
stack trace:
areIterablesEqual@https://<host-name>:<port>/testing-area/vendor.js:13061:9
devModeEqual@https://<host-name>:<port>/testing-area/vendor.js:12990:9
{more stuff}
"ERROR CONTEXT" Object(view: Object, nodeIndex: 4, nodeDef: Object, elDef:
Object, elView: Object) (main.js:393)
"ERROR" TypeError: a[getSymbolIterator(...)] is not a function (main.js:393)
stack trace:
{same stuff}
解决方案
为了解决这个问题,我刚刚将我的 Firefox 浏览器从 31 版升级到了 38.5.2 版。一旦我这样做并重新加载了我的应用程序,就没有出现任何错误(之前在我的问题中列出)。而且,我的静态数据终于如期而至。
推荐阅读
- ios - SwiftUI + Combine:如何将数据分配给带有动画的模型
- r - 使用 tidymodels 和堆栈时出错:位置 3 不存在
- shell - 如果使用 nohup 在后台执行脚本会卡住
- javascript - 在 JavaScript 中,如何在使用 fetch 发布时仅更新 JSON 数组中的一个值?
- liferay - 更改管理页面中的 url (Liferay 7.1GA)
- unix - 如何用相同的字符串查找和替换具有特定模式的字符串
- julia - 如何在 Julia 中使用求解 cvxopt?
- flutter - 在颤动中滚动列表视图时我需要动画项目
- java - 反转二维数组中的数字
- angular - 如何使用 RouterTestingModule 测试路由导航