【问题标题】:Can asyncPipe in angular2 can improve UI performance?angular2 中的 asyncPipe 可以提高 UI 性能吗?
【发布时间】:2017-03-14 12:38:02
【问题描述】:

Tour Of Heros angular2 example 中,通过promise 检索到的数据被提取为Hero[],如Extracting the data in the then callback 中所述。除了提取逻辑,Observable 可以与不纯的 asyncPipe 一起使用。

如果我使用Observable,是否有任何 UI 性能提升?如果有,怎么做?

【问题讨论】:

    标签: angular asynchronous rxjs observable


    【解决方案1】:

    您可以设置组件changeDetection: ChangeDetectionStrategy.OnPush 以避免为此组件及其子组件运行不必要的更改检测。 |async 管道然后调用ChangeDetectorRef.markForCheck() 来注册组件以在下一个更改检测周期中进行更改检测,但仅在新值到达时。 这种方式显着减少了变更检测工作,因为它只在必要时运行,从而提高了性能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      • 2019-10-19
      相关资源
      最近更新 更多