2017-03-17 54 views
0

在我的離子應用程序中,當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

<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> 

回答

0

記住離子chaches的意見,所以控制器被稱爲只在應用程序啓動或當您禁用緩存。

您可以偵聽$ ionicView.enter事件,並在回調函數中插入每次激活視圖時需要執行的代碼。

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

我正在使用'$ ionicConfigProvider.views.maxCache(0);'和cache在離子視圖中設置爲false。我實際上使用谷歌地圖api,所以我怎麼能在'$ ionicView.enter'中輸入它 – sam