本文介绍了加载内容后调用的 AngularJs 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要在页面内容加载后调用的函数.我读到 $viewContentLoaded 并且它对我不起作用.我正在寻找类似
的东西document.addEventListener('DOMContentLoaded', function () {//内容在这里}, 错误的);
以上调用在 AngularJs 控制器中对我不起作用.
解决方案
根据 $viewContentLoaded,它应该可以工作
每次重新加载 ngView 内容时发出.
发出
$viewContentLoaded
事件,这意味着要接收此事件,您需要像
<div ng-view></div>
从 MainCtrl
可以监听事件
$scope.$on('$viewContentLoaded', function(){//这里您的视图内容已完全加载!});
查看演示
I have a function which I want to call after page content is loaded. I read about $viewContentLoaded and it doesn't work for me. I am looking for something like
document.addEventListener('DOMContentLoaded', function () {
//Content goes here
}, false);
Above call doesn't work for me in AngularJs controller.
解决方案
According to documentation of $viewContentLoaded, it supposed to work
$viewContentLoaded
event is emitted that means to receive this event you need a parent controller like
<div ng-controller="MainCtrl">
<div ng-view></div>
</div>
From MainCtrl
you can listen the event
$scope.$on('$viewContentLoaded', function(){
//Here your view content is fully loaded !!
});
Check the Demo
这篇关于加载内容后调用的 AngularJs 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!