[英]How to implement ngFor callback in Angular4?
I know that there are several questions about this point. 我知道关于这一点有几个问题。 I have a table and for each row I've a button to show row's details with a modal, so I need to call a function to initialize these buttons when ngFor has finished to render them.
我有一张桌子,每行都有一个按钮,用于显示带有模式的行的详细信息,因此当ngFor完成渲染它们时,我需要调用一个函数来初始化这些按钮。 This external function will add listeners "onClick" to every button to open modal, sadly I can't edit this external function anyway.
此外部功能将在每个按钮上添加监听器“ onClick”以打开模式,遗憾的是我还是无法编辑此外部功能。
ngFor
is synchounous, so as soon as the ngForOf
array is updated during the ngDoCheck
lifecycle it will render all items. ngFor
是同步的,因此在ngDoCheck
生命周期内更新ngForOf
数组后,它将立即呈现所有项目。 So you can safely use ngAfterViewChecked
in the parent component to perform your logic. 因此,您可以安全地使用父组件中的
ngAfterViewChecked
来执行逻辑。 When this lifecycle hook is triggered ngFor
has added items to the DOM. 触发此生命周期挂钩时,
ngFor
已将项目添加到DOM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.