I need to apply jquery
plugin to radio buttons in Angular2
using Typescript
.
If I assign in ngAfterViewChecked
, it is called many times and the control is refreshed multiple times.
What is the alternate solution for calling the javascript method after DOM is ready?
ngAfterViewChecked() would be invoked once the DOM tree get any change. So if the DOM tree got change for many times, the ngAfterViewChecked() method would be invoked many times.
ngAfterViewChecked() is called after ngAfterContentInit. ngAfterViewChecked() is called after every subsequent ngAfterContentChecked. Triggering the clickMe() function will trigger ngAfterViewChecked().
ngAfterViewInit()link A callback method that is invoked immediately after Angular has completed initialization of a component's view. It is invoked only once when the view is instantiated.
ngAfterViewChecked()linkA callback method that is invoked immediately after the default change detector has completed one change-check cycle for a component's view.
Try ngAfterViewInit
and have a look here.
ngAfterViewChecked()
would be invoked once the DOM tree get any change.
So if the DOM tree got change for many times, the ngAfterViewChecked() method would be invoked many times.
Suggest not to put business logic in this method. But only the screen refresh related logic instead, like to scroll the window to bottom if new message is coming in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With