Search code examples
javascriptcordovaonsen-ui

Can you use ons-postpush to find elements on pushed via javascript?


I am using Onsen UI for app development. This app makes use of the JQuery UI slider. This slider needs to be initialized via javascript, but when I load the next page the javascript code gets executed before the page is fully loaded. Therefore the javascript code is not able to find the div in which the slider will be loaded.

My question: Can you use the ons-postpush attribute to solve this? And how do you use it? Since this isn't specified in the Onsen UI docs...

Thank you so much in advance!


Solution

  • You need Onsen UI 1.3 to do this:

    $(document).on('ons-navigator:postpush', 'ons-navigator', function(event) { 
        console.log("Pushed!"); 
    });
    

    Hope it helps!

    --- Edit:

    Fixed by @jasper for this case:

    ons.ready(function() { 
        myNavigator.on('postpush', function(event) { 
            console.log("test"); 
        }); 
    });