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)
});
にコードを変更し
そして、それは
'$の範囲を動作するはずです。$( "$ ionicView.enter"、機能(){ $スコープに。$ root.showRight = false; });これだけで動作しますか? – Jennifer
はい、単に '' $ scope.showRight = false; ''を '' $ scope。$ on( "$ ionicView.enter"、function(){$ scope. $ root.showRight = falseに置き換えてください;}); '' 'とても冗長であることをお詫びします。 – Kevin
実際に問題を解決しました!ありがとう!しかし、もし私が10ページ/コントローラを持っていると想像していますか?すべてのコントローラーの初めにそれを繰り返さなければなりませんか? – Jennifer