javascript – 一旦在Angular 4中动态完全呈现HTML,我怎样才能在jQuery中调用函数?

栏目: jQuery · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/48059108/how-can-i-call-a-function-in-jquery-once-html-is-completely-rendered-dynamically

我使用Angular 4作为我的网页模板.

在构造函数内部调用HTTP get方法后生成HTML,其响应创建 HTML

.

以上工作正常.

我也在使用带有Angular的jQuery并试图在这个页面上初始化一个函数.

$(function() {
    Books.init();
});

我试过在各种生命周期钩子里面调用上面的代码.例如,ngOnInit(),ngOnChanges(),ngDoCheck,ngAfterViewInit(),ngAfterContentInit()但仍然在API响应完全呈现视图之前调用代码.

有没有办法得到一个事件,以确保视图完全呈现,然后我可以加载我的jQuery?

请注意:我已经在setTimeOut调用中调用了这个函数,时间延迟很小,这就可以了.

我遇到了同样的问题.

我没有任何解决方案所以我玩变量.

首先要考虑要渲染的元素的长度.

bookCount: number = 0;

然后在ngAfterContentChecked()

ngAfterContentChecked() {
if(this.bookCount > 0 && this.bookCount == document.getElementsByClassName('bk-book').length)
{
  this.getInitdata();
}

这暂时对我有用,仍在寻找更好的解决方案.

翻译自:https://stackoverflow.com/questions/48059108/how-can-i-call-a-function-in-jquery-once-html-is-completely-rendered-dynamically


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Security Testing Cookbook

Web Security Testing Cookbook

Paco Hope、Ben Walther / O'Reilly Media / 2008-10-24 / USD 39.99

Among the tests you perform on web applications, security testing is perhaps the most important, yet it's often the most neglected. The recipes in the Web Security Testing Cookbook demonstrate how dev......一起来看看 《Web Security Testing Cookbook》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

SHA 加密
SHA 加密

SHA 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具