问题
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?
回答1:
Try ngAfterViewInit
and have a look here.
回答2:
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.
回答3:
I have been using ngAfterViewChecked
when I depend on the DOM being ready.
import { Component, AfterViewChecked } from '@angular/core';
export class NavBar implements AfterViewChecked{
ngAfterViewChecked(){
// jquery code here
}
}
来源:https://stackoverflow.com/questions/41391939/angular2-ngafterviewchecked-is-called-many-times-how-to-call-a-method-just-o