【问题标题】:Using Angular 6, why does http.get() not retrieve my static data?使用 Angular 6,为什么 http.get() 不检索我的静态数据?
【发布时间】:2018-06-25 18:55:26
【问题描述】:

我在使用 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 调用。

如果我运行服务器并使用本地浏览器,一切正常!

这可能是 polyfill 问题、另一个 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}

【问题讨论】:

  • 请也发布您的服务。
  • 如果需要提交更多信息,请让我知道我还可以提供什么。

标签: angular https


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 2014-12-27
    • 2019-07-08
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多