8

I have a fairly simple todo app using angular.js for which I am using the ui-router library. I looked through the ui-router example on github (https://github.com/angular-ui/ui-router/tree/master/sample) but was unable to figure out what I am doing wrong. In my app I have a sidebar navigation view (with the list of things todo) and a content view (which displays the todo item's details when clicked). The problem I have is that when I navigate to /todo/exampleItem the content view updates and the navigation panel is reloaded as well. This doesn't effect the functionality of the app but I would like to avoid the navigation panel flickering each time you click on an item.

Here is my code to handle the state changes:

app.config(function ($stateProvider) {
    $stateProvider
    .state('todo', {
        url: "/todo", 
        views: {
            "navPanel": {
                templateUrl: "./navPanel.html",
                controller: 'PanelController'
            }
        }
    })
    .state('todo/:item', {
        url: "/todo/:item", 
        views: {
            "PanelView": {
                templateUrl: "./navPanel.html",
                controller: 'PanelController'
            },
            "ContentView": {
                templateUrl: "./content.html",
                controller: 'ContentController'
            }
        }
    })

});

In my index.html my views are set up as follows:

  <div class="column" data-ui-view="PanelView"></div>
  <div class="column" data-ui-view="ContentView"></div>

Is there some way I can stop the navPanel view from being reloaded each time a new item is clicked?

Zanon
  • 29,231
  • 20
  • 113
  • 126
ORL
  • 598
  • 2
  • 8
  • 22

1 Answers1

4

Based on the voted answer of that question angularjs ui-router - how to build master state which is global across app

app.config(['$stateProvider', function ($stateProvider) {
    $stateProvider
    .state('todo', {
        abstract: true,
        views: {
            "navPanel": {
                templateUrl: "./navPanel.html",
                controller: 'PanelController'
            }
        }
    })
    .state('todo/:item', {
        url: "/todo/:item", 
        views: {
            "ContentView@": {
                templateUrl: "./content.html",
                controller: 'ContentController'
            }
        }
    })

}]);
Community
  • 1
  • 1
Sydney
  • 11,964
  • 19
  • 90
  • 142
  • When I add the abstract true line it makes my navPanel vanish. I think I must be missing something conceptually on how nested views work. I will keep researching and post back when I have a solution. Thanks for you help though! – ORL Jul 04 '13 at 23:20
  • Can you try changing `navPanel` to `PanelView` in the abstract state? – Sydney Jul 05 '13 at 05:47
  • Wow, that was the issue, I can't believe I missed that. Thanks! – ORL Jul 05 '13 at 17:05
  • I have exactly the same problem. But when I use abstract:true, the console show me an error says : `Cannot transition to abstract state 'myState'`. How did you achieve to display correctly your grid and only reload the form when choose to edit an item? – Ganbin Mar 03 '16 at 16:34