我正在使用带有模板html的路线
$routeProvider.when('/newroute',
{
templateUrl: 'template/newroute.html',
controller: 'myController'
});
我需要做一些事情来在渲染模板html后使用jquery操作DOM(我知道这不是一个好习惯,但我找不到我的question的答案)
但是,我无法在呈现模板html后找到正确的事件。 我试过跟随,这不起作用。
$scope.$on('$viewContentLoaded', function () {
doSomething(); //does not work
});
当我调试到viewContentLoaded时,模板html DOM仍然是不可见的。有什么想法吗?
答案 0 :(得分:0)
我遇到了同样的问题。我最终使用setTimeout
来运行一些jQuery
setTimeout(function () {
var l=$('.accordion-section').length;
if(l>0){
$('.accordion-section').equalHeights();
}
},500);
我将setTimout调用放入控制器的初始化中。
这里有一些其他答案,但$timeout
对我不起作用。
AngularJS: How to run additional code after AngularJS has rendered a template?