【问题标题】:Get method do not have time to pull data from the serverGet 方法来不及从服务器拉取数据
【发布时间】:2019-03-07 12:34:19
【问题描述】:

我有一个非常基本的问题,但我不知道最好的方法。我的问题在于单击要发送数据并从服务器获取相同数据的按钮。在某些情况下,我的后端可以有时间将数据存储在我的数据库中,当我检索数据时,我会在没有最后更改的情况下提取数据。

  storeCategory() {
 this.categoryService.storeCategory(this.currentFileUpload, this.category).subscribe();  
this.adminService.getCategoryFromServer();

有人知道有提议吗?

【问题讨论】:

  • 您的服务器能否将该数据作为对第一个请求的响应返回?
  • 为此,我可以在后端更改我的方法。 Maby 就是一个很好的解决方案。
  • 如果你能做到,我认为这是最简单和最安全的解决方案
  • 谢谢,我想是的。
  • 您也可以在 storeCategory() 之后管道并执行 getCategoryFromServer ,即 this.categoryService.storeCategory(this.currentFileUpload, this.category).pipe(map(() => this.adminService.getCategoryFromServer( )).subscribe((数据) => 数据)

标签: angular http observable


【解决方案1】:

您需要在存储完成后通过将getCategoryFromServer() 放入storeCategory(this.currentFileUpload, this.category)subscribe() 中来检索数据:

storeCategory() {

    this.categoryService.storeCategory(this.currentFileUpload, this.category)
    .subscribe(() => {

        this.adminService.getCategoryFromServer();

    });
}

这样你应该得到最新的变化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    • 1970-01-01
    • 2013-07-20
    相关资源
    最近更新 更多