最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Perform onload() in ionic - Stack Overflow

programmeradmin4浏览0评论

I want to load a function when a page loads.So how to use native javascript onload function in ionic.Here is 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 the this when page is loaded.How it possible in ionicframework?

I want to load a function when a page loads.So how to use native javascript onload function in ionic.Here is 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 the this when page is loaded.How it possible in ionicframework?

Share Improve this question edited Sep 1, 2014 at 7:50 shamon shamsudeen asked Sep 1, 2014 at 7:39 shamon shamsudeenshamon shamsudeen 5,85820 gold badges74 silver badges144 bronze badges 1
  • ngAfterViewChecked() { console.log('view loaded'); } – stackoverflow account Commented Apr 19, 2021 at 7:10
Add a ment  | 

4 Answers 4

Reset to default 3

What about using the controller associated with that view?

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

Please give this a try.

$ionicView.enter

$ionicView.loaded

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

do you mean on page load, or on view loaded?

pageload is simple, you could do a

<body onload='testload()'>

probably you should check out $ionicPlatform if you want to execute some function upon device ready

$ionicPlatform.ready([callback])

Or just a page load...in your controller, inject $scope and listen to $ionicView.loaded

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

评论列表(0)

  1. 暂无评论