我试图在完成模板渲染后在angularJs中获取页面完成事件。
以下是我尝试的代码: -
app.controller('Mycontroller',function($scope,$http,$stateParams,$sce,$timeout){
var request = $http({
url:"/test.php",
headers: {'Content-Type' : 'application/x-www-form-urlencoded'}
});
request.success(function(data){
$scope.testhtml = $sce.trustAsHtml(data);
});
$scope.$on('$viewContentLoaded', function(event) {
$('#firstcontent').trigger('create');
alert('fullyloaded'); // this alert I am getting before template rendering , (I want this alert after template rendering )
});
});
答案 0 :(得分:0)
如果您在$timeout
内执行代码,则可以确定该模板已经呈现:
request.success(function(data){
// executed within the currently running digest
$scope.testhtml = $sce.trustAsHtml(data);
$timeout(function(){
// executes after the previously mentioned digest is complete
// and after the DOM has been rendered
$('#firstcontent').trigger('create');
alert('fullyloaded');
});
});
您可能会发现以下答案另外有用: