AngularJs等待dom内容加载



我想隐藏并创建AngularJS加载的元素。

当我想执行JS函数时,DOM并没有完全加载。

问题:我的查询选择器无法检测元素。我不想使用timeout,因为它取决于用户的网络。

我的代码:

app.controller('RootController', function($scope, $http, $filter) {
$scope.init = function() {
// NULL here, but after dom loaded in the chrome console I get an array of elements
console.log(document.querySelectorAll('table .actionslist'));
}
});

您可以使用以下代码;

这将在viewContentLoaded上添加一个侦听器,并在DOM完全加载时执行其中的代码。

$scope.$on('$viewContentLoaded', function () {  
console.log(document.querySelectorAll('table .actionslist'));
});

最新更新