首页 > 解决方案 > Angular:在元素位于 DOM 之后运行 ChangeDetection?

问题描述

我在模态对话框中有一个组件。我注意到组件的 @Inputs 在元素实际位于 DOM 之前触发!这会导致不良的布局行为。在运行更改检测之前,如何确保元素在 DOM 中?

笔记:

我目前正在使用这个黑客。我认为有一种更优雅的方式:

class MyDialog implements AfterViewInit {

   @ViewChild(ChartElement)
   ChartElement chart;

   @override
   void ngAfterViewInit() async {
       while(document.getElementById('#myElement') == null) {
           await Future.delayed(Duration(milliseconds: 100));
       }
       chart.draw();
   }
}

标签: angularangular-dartangular-changedetection

解决方案


推荐阅读