javascriptionic-framework

How to get onload function working in Ionic?


I am having some troubles here:

function load(){
    var elements=document.getElementsByClassName('inputfield');
        for(let i=0;i<elements.length;i++){
            elements[i].addEventListener("keydown",keydown);
        }
  }

window.onload = load;

This is my JavaScript which works perfectly fine with this HTML outside my Ionic app:

        <input class="zipCode inputfield" />

Yet, it is not working in Ionic! I have no errors in the console or whatsoever...

I tried this too:

<body onload="load();">
   <input class="zipCode inputfield" />
</body>

But it didn't do the trick either.

I am out of options, as this is perfectly valid JS. How can I fix this?


Solution

  • document.addEventListener("deviceready", load, false) ;
    
    function load(){
        var elements=document.getElementsByClassName('inputfield');
        for(let i=0;i<elements.length;i++){
            elements[i].addEventListener("keydown",keydown);
        }
    }