I'm developing an Ionic app, using a side menu. But the change of states is not working as I want it to.
This is my parent-child relationship defined in my $stateProvider in the app.js file:
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.home', {
url: "/home",
views: {
'menuContent':{
templateUrl: "templates/home.html",
controller: 'AppCtrl'
}
}
})
.state('app.map', {
url: "/map",
views: {
'menuContent':{
templateUrl: "templates/map.html",
controller: 'MapCtrl'
}
}
});
$urlRouterProvider.otherwise('/app/home');
});
These are the steps to follow:
When I click in the area element defined in the home.html template:
<area id="ImgMap" shape="poly" coords="456,326,521,69,274,10,259,91,290,216,388,326"
ng-click="loadMap(0)" ui-sref="app.mapa" ui-sref-opts="{ reload: true }" title="Map" alt="Map"/>
//I've also tried with href='#/app/map'
the app goes to the app.map state, loads the map.html template and executes correctly the MapCtrl controller code.
Then, if I go back to the home.html page through the side menu (code as follow):
<ion-side-menus>
<ion-pane ion-side-menu-content>
<ion-nav-bar class="bar-positive nav-title-slide-ios7">
</ion-nav-bar>
<ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
</ion-pane>
<ion-side-menu side="left" >
<ion-content class="mymenu">
<div id="menu-list">
<ion-list class="list">
<ion-item item-type="item-icon-left" nav-clear menu-close href="#/app/home">
<i class="icon ion-home"></i><span>Home</span>
</ion-item>
</ion-list>
</div>
</ion-content>
</ion-side-menu>
</ion-side-menus>
And I click again in the area element defined in the home.html page, just like the first. Only this time it navigates correctly to the map page, but the controller MapCtrl doesn't execute its code, so I can't reload the map info if needed.
So, in resume. From my home state I go to the map state, and everything executes correctly. But if I go back to the home state and repeat the process, the controller of the map state doesn't execute its code this time.
What am I doing wrong?
I've tried different solutions, trying to use template option instead of templateUrl, force the change and reload of state with $state.go(), etc... but none of them seems to work as I expect!