Reputation: 19587
I am using ngAfterViewChecked to call a function that initialize some css role using jquery
my code is like this
ngAfterViewChecked(){
console.log("ngAfterViewChecked");
this.callJqueryMethod();
}
callJqueryMethod(){
jQuery(".leftText").each(function () {
var $this = jQuery(this);
$this.height($this.parent("div").find(".boxWarp").height()+42);
});
jQuery(window).resize(function () {
jQuery(".leftText ").each(function () {
var $this = jQuery(this);
$this.height($this.parent("div").find(".boxWarp").height() + 42);
});
});
}
for some reason ngAfterViewChecked keep calling over and over in a loop.
I must use this lifecycle hook, in other lifecycle the doom isn't ready.
does anyone encountered that kind of problem?I can't see a errors in the console
Upvotes: 1
Views: 2384
Reputation: 208
Looks like jquery is triggering the update of your DOM which in fact calls ngAfterViewChecked() and this one calls jquery again, so you have a loop between jquery and ngAfterViewChecked().
Try to avoid jquery with this hook.
Upvotes: 2