简体   繁体   English

返回后无法重新加载ionic应用程序脚本

[英]ionic app script not reloaded after going back

In my ionic app when script included in index.html is loaded for the first time but after coming back to same screen script is not running. 在我的离子应用程序中,首次加载index.html包含的脚本时,但回到同一屏幕后,脚本未运行。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title></title>
        <link href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">
        <script src="lib/ionic/js/ionic.bundle.js"></script>
        <script src="cordova.js"></script>
        <script src="js/app.js"></script>
        <script src="js/controllers.js"></script>
        <script>alert(1)</script>
    </head>
    <body ng-app="starter"> 
<ion-nav-view> </ion-nav-view>
    </body>
</html>

homepage.html homepage.html

  <ion-view>
 <ion-nav-bar align-title="center" class=" bar-royal">
     <ion-nav-title>
  <span>Find Hotels</span>
 </ion-nav-title>
  </ion-nav-bar >
<ion-content  padding="true">
alerted 1 on initial load but not after moving back to same page
 </ion-content>
</ion-view>

Keep in mind that Ionic chaches the views, so controllers are called only on app start or when you disable the caching. 请记住,Ionic会阻塞视图,因此仅在应用程序启动或禁用缓存时才调用控制器。

You can listen to the $ionicView.enter event and insert in the callback function the code that you need to execute every time the view is active. 您可以侦听$ ionicView.enter事件,并在回调函数中插入每次视图处于活动状态时需要执行的代码。

  $scope.$on('$ionicView.enter', function (e) {
  //insert here the code to execute every time the page is active
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM