【问题标题】:AngularJs waith before dom content loaded [duplicate]加载dom内容之前的AngularJs等待[重复]
【发布时间】:2020-04-04 12:35:45
【问题描述】:

我想隐藏和创建由 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'));
  }
});

【问题讨论】:

标签: angularjs


【解决方案1】:

可以使用以下代码;

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 2011-11-12
    • 2020-02-08
    • 2013-09-08
    • 2014-10-15
    相关资源
    最近更新 更多