【问题标题】:Using Async pipe in ts file of Angular在 Angular 的 ts 文件中使用异步管道
【发布时间】:2022-07-24 23:20:43
【问题描述】:

当我们在 html 中使用异步管道时,我们使用语法“Products$ | async as products”。

如果我想在 ts 文件中使用相同的产品怎么办?这个可以吗?

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    简单来说,我们可以在 Products$ 对象为 observable 数组时使用异步管道,如果你想在 ts 文件中使用,可以订阅并获取数据,如下图所示

    Products$.subscribe((products) => {
       console.log(Products);
    });
    

    【讨论】:

      猜你喜欢
      • 2020-04-18
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2017-05-05
      • 2021-05-13
      • 1970-01-01
      • 2020-03-26
      • 2020-11-13
      相关资源
      最近更新 更多