【问题标题】:Angular 4 API infinite call once API service is disconnected一旦API服务断开,Angular 4 API无限调用
【发布时间】:2018-07-02 20:20:20
【问题描述】:

我正在使用 c# web api 作为服务来开发 Angular 4 应用程序,如果 API 应用程序停止,然后使用 Angular UI 中的按钮单击进行 API 调用,我遇到了一个问题,例如在登录并有多个 API 调用之后导致无限的 API 调用就像相同的 API 调用一次又一次地迭代。

【问题讨论】:

  • 这不应该发生,您的订阅方式可能有问题。除非你有重试。
  • export declare function catchError(selector: (err: any, caught: Observable) => ObservableInput): OperatorFunction;
  • 虽然http服务发生了一些错误,这个函数正在被调用,谁能帮我理解这个
  • catch 错误输出是什么?那应该是你的答案
  • 嗨@TaranjitKang 感谢您抽出宝贵的时间,问题仍然存在,即使没有运行 API 背景的登录按钮也会导致问题

标签: angular asp.net-web-api


【解决方案1】:

遇到问题了,为了路由器重载,我们在构造函数中给出了代码:

this.navigationSubscription = this.router.events.subscribe((e: any) => {
  // If it is a NavigationEnd event re-initalise the component
  if (e instanceof NavigationEnd) {
    this.ngOnInit();
  }
});

这导致了一个循环......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-20
    • 2016-01-08
    • 2019-11-30
    • 1970-01-01
    • 2018-02-14
    • 1970-01-01
    • 2016-08-25
    • 2018-03-16
    相关资源
    最近更新 更多