Do onload () in ionic

I want to load a function when the page is loaded. Since using the built-in onload javascript function in ionic.Here is a sample html page.

<ion-view title="Account" >
  <ion-content class="has-header padding">
    <h1>Account</h1>
    <button id="bt">test</button>
</div>
  </ion-content>
</ion-view>

      

here is my javascript file

function testload(){

  alert("page loaded");
 }

      

I want to load this on page load. How is this possible in an ion chamber?

+3


source to share


4 answers


How about using a controller associated with this view?



.controller('YourCtrl', function($scope, $stateParams, Something) {
    alert("page loaded");
})

      

+3


source


Please try.

$ionicView.enter

$ionicView.loaded

      



http://ionicframework.com/docs/api/directive/ionView/

+3


source


You should probably check $ ionicPlatform if you want to execute some function after the device is ready

$ionicPlatform.ready([callback])

      

Or just loading the page ... in your controller, inject $ scope and listen for $ ionicView.loaded

app.controller('controller', function($scope) {
  $scope.$on('$ionicView.loaded', function(event) {
  });
});

      

+1


source


Do you mean on page load or on load?

pageload is simple, you can do

<body onload='testload()'>

      

-1


source







All Articles