首页 > 解决方案 > 使用 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}

标签: angularhttps

解决方案


为了解决这个问题,我刚刚将我的 Firefox 浏览器从 31 版升级到了 38.5.2 版。一旦我这样做并重新加载了我的应用程序,就没有出现任何错误(之前在我的问题中列出)。而且,我的静态数据终于如期而至。


推荐阅读