Based on our previous discussions, I want to give you some insight into how to use the UI-Router here. I believe that I understand your challenge correctly ... a working example . If this does not fully fit, please take it as an inspiration.
DISCLAIMER: With the plunker, I could not achieve this: http://m.amsterdamfoodie.nl/ , but the principle should be that the example is similar
So, there is a definition of state (we have only two states)
$stateProvider .state('main', { url: '/', views: { '@' : { templateUrl: 'tpl.layout.html', controller: 'MainCtrl', }, 'right@main' : { templateUrl: 'tpl.right.html',}, 'map@main' : { templateUrl: 'tpl.map.html', controller: 'MapCtrl', }, 'list@main' : { templateUrl: 'tpl.list.html', controller: 'ListCtrl', }, }, }) .state('main.criteria', { url: '^/criteria/:criteria/:value', views: { 'map' : { templateUrl: 'tpl.map.html', controller: 'MapCtrl', }, 'list' : { templateUrl: 'tpl.list.html', controller: 'ListCtrl', }, }, }) }];
This will be our main tpl.layout.html
<div> <section class="main"> <section class="map"> <div ui-view="map"></div> </section> <section class="list"> <div ui-view="list"></div> </section> </section> <section class="right"> <div ui-view="right"></div> </section> </div>
As we can see, the ground state defines these nested representations of the ground state: 'viewName @main ', for example. 'right@main'
Also subview, main.criteria inserts a layout into the views.
Its url starts with the ^ sign ( url : '^/criteria/:criteria/:value' ), which allows you to have a / forward slash for the main rather than a double forward slash for the child
And there are also controllers, they are a little naive here, but they should show that there can be real data loading in the background (based on criteria).
The most important thing here is that PARENT MainCtrl creates $scope.Model = {} . This property will (thanks to inheritance) be shared between parents and children. This is why all this will work:
app.controller('MainCtrl', function($scope) { $scope.Model = {}; $scope.Model.data = ['Rest1', 'Rest2', 'Rest3', 'Rest4', 'Rest5']; $scope.Model.randOrd = function (){ return (Math.round(Math.random())-0.5); }; }) .controller('ListCtrl', function($scope, $stateParams) { $scope.Model.list = [] $scope.Model.data .sort( $scope.Model.randOrd ) .forEach(function(i) {$scope.Model.list.push(i + " - " + $stateParams.value || "root")}) $scope.Model.selected = $scope.Model.list[0]; $scope.Model.select = function(index){ $scope.Model.selected = $scope.Model.list[index]; } })
This should understand how we can use the functions provided by us using the UI-Router:
Check out the above extract here in a working example
Expand: The new plunker is here
If we do not want the map display to be recreated, we can simply lower this form to the def child state:
.state('main.criteria', { url: '^/criteria/:criteria/:value', views: { // 'map' : { // templateUrl: 'tpl.map.html', // controller: 'MapCtrl', //}, 'list' : { templateUrl: 'tpl.list.html', controller: 'ListCtrl', }, }, })
Now our VIEW map will simply receive changes in the model (can be viewed), but the view and controller will not restart
ALSO, there is another plunker http://plnkr.co/edit/y0GzHv?p=preview that uses controllerAs
.state('main', { url: '/', views: { '@' : { templateUrl: 'tpl.layout.html', controller: 'MainCtrl', controllerAs: 'main', // here }, ... }, }) .state('main.criteria', { url: '^/criteria/:criteria/:value', views: { 'list' : { templateUrl: 'tpl.list.html', controller: 'ListCtrl', controllerAs: 'list', // here }, }, })
and this can be used as follows:
<h4>{{main.hello()}}</h4> <h4>{{list.hello()}}</h4>
The last plunker is here