代码之家  ›  专栏  ›  技术社区  ›  DarkW1nter

从html中的json对象获取值

  •  0
  • DarkW1nter  · 技术社区  · 6 年前

    如何仅显示值 100 在下面的分区中?

    <div> {{uploadProgress | async | json}} </div>
    

    显示的当前值为:

    [{“filename”:“Mailman Linux.jpg”,“progress”:100}]

    在.ts文件的我的界面下方:

    interface IUploadProgress {
      filename: string;
      progress: number;
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Flyii    6 年前

    uploadProgress | async 获取流的对象。

    在异步管道之后,它可能会打印出来 [Object object]

    由于这现在是一个对象,您可以像任何其他对象一样简单地获取进度属性。

    结果应该如下所示:

      <div> {{(uploadProgress | async).progress}} </div>
    

    另外,如果你的可观察对象不是行为主体,那么你可能需要添加一个 safe navigation 具有 ? 在安装管道后,防止 undefined 错误:

      <div> {{(uploadProgress | async)?.progress}} </div>
    

    正如Shamposham正确提到的,结果似乎是一个数组。

       <div> {{(uploadProgress | async)[0]?.progress}} </div>
    
    推荐文章