How to get the dimension of dynamic rendered element in Angular

前端 未结 2 647
陌清茗
陌清茗 2021-01-15 16:12

just imagine: 1. in component.html, you have

{{text}}

2条回答
  •  悲哀的现实
    2021-01-15 16:30

    It returns the previous values because it takes time for the browser to compute the new style.

    The RequestAnimationFrame API is what you are looking for.

    Once you've set the new text, use the RequestAnimationFrameAPI, it's a callback triggered once the browser is ready, basically when its render queue is empty.

    this.text = "blablablabla...."
    window.requestAnimationFrame(() => {
      // access the new css values here
    })
    

提交回复
热议问题