Doing JavaScript stuff after the DOM and Ionic has fully loaded


#1

Hi there!

I’m new to Ionic and absolutely love it so far. I’m struggling to work out why my JavaScript is not firing after the Ionic framework has been loaded.

I’m using jQuery for this one. And it looks like the following.

Load Order: jQuery, Ionic, My Script

My Script:

ionic.DomUtil.ready(function(){

    setTimeout(function(){console.log($('body').html())},0);
    //console.log($('body').html());

});

So as you can see I commented out the second line for now… For some reason the correct HTML is only shown when I set a timeout of 0 or more milliseconds. And when I don’t wrap it around the timeout function it just shows an empty

<ion-nav-view></ion-nav-view>

Instead of…

<ion-nav-view><h1>Something something something</h1></ion-nav-view>

This is a very simplified view of what I need to do. Just getting the body’s correct HTML to show would be a great start! Any ideas?


#2

maybe replace ionic.DomUtil.ready(function(){ with $ionicPlatform.ready(function() { , i am not sure.


#3

I have tried using…

ionic.Platform.ready()
ionic.DomUtil.ready()
jQuery.ready()
angular.ready()

Nothing seems to work UNLESS I put the timout of 0 or more.