2016-04-24 1 views
0

https://codepen.io/anon/pen/VaBOwv

.controller('CheckinCtrl', function($scope) { 
    $scope.$root.showRight = true; 

}) 

.controller('AttendeesCtrl', function($scope) { 

    $scope.$root.showRight = false; 
    alert($scope.$root.showRight) 
}); 

間のナビゲートを更新されません。しかし、私はそれをしようとすると、スコープの値がキャッシュのために更新されていないことがわかりました。私はこの状態でcache:falseを使用するのが嫌ですしかし、どのようにこの問題を解決するには?新しいビューに入ると

答えて

4

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

あなたのコードは、ユーザーがビューに入るたびに実行させたい場合は、$ionicView.enterは、それはあなたのコードを置く場所です、$スコープに放送されます。

angular.module('ionicApp', ['ionic']) 

.config(function($stateProvider, $urlRouterProvider) { 

    $stateProvider 
    .state('eventmenu', { 
     url: "/event", 
     abstract: true, 
     templateUrl: "templates/event-menu.html" 
    }) 
    .state('eventmenu.home', { 
     url: "/home", 
     views: { 
     'menuContent' :{ 
      templateUrl: "templates/home.html" 
     } 
     } 
    }) 
    .state('eventmenu.checkin', { 
     url: "/check-in", 
     views: { 
     'menuContent' :{ 
      templateUrl: "templates/check-in.html", 
      controller: "CheckinCtrl" 
     } 
     } 
    }) 
    .state('eventmenu.attendees', { 
     url: "/attendees", 
     views: { 
     'menuContent' :{ 
      templateUrl: "templates/attendees.html", 
      controller: "AttendeesCtrl" 
     } 
     } 
    }) 

    $urlRouterProvider.otherwise("/event/home"); 
}) 

.controller('MainCtrl', function($scope, $ionicSideMenuDelegate) { 
    $scope.$root.showRight = true; 

    $scope.toggleLeft = function() { 
    $ionicSideMenuDelegate.toggleLeft(); 
    }; 
}) 

.controller('CheckinCtrl', function($scope) { 
    $scope.$on("$ionicView.enter",function(){ 

    $scope.$root.showRight = true; 
    }); 

}) 

.controller('AttendeesCtrl', function($scope) { 

    $scope.$on("$ionicView.enter",function(){ 

    $scope.$root.showRight = false; 
    }); 
    // alert($scope.$root.showRight) 
}); 

にコードを変更し

そして、それは

+0

'$の範囲を動作するはずです。$( "$ ionicView.enter"、機能(){ $スコープに。$ root.showRight = false; });これだけで動作しますか? – Jennifer

+0

はい、単に '' $ scope.showRight = false; ''を '' $ scope。$ on( "$ ionicView.enter"、function(){$ scope. $ root.showRight = falseに置き換えてください;}); '' 'とても冗長であることをお詫びします。 – Kevin

+0

実際に問題を解決しました!ありがとう!しかし、もし私が10ページ/コントローラを持っていると想像していますか?すべてのコントローラーの初めにそれを繰り返さなければなりませんか? – Jennifer

関連する問題