2

I have some html like this (I won't even bother to post the JS since it's an overcomplicated mess):

<html>
  <body>
    <div class="container">
      <h3 class="text-center">Administration</h3>
    </div>
    <div class="form-inline text-center">
      <div class="form-group">
        <label>Managing Business</label>
        <select ng-options="business.name for business in businesses" ng-model="managingBusiness" class="form-control restaurant-select"></select>
        <label>Program</label>
        <select ng-options="program.description for program in selectablePrograms" ng-model="managingProgram" class="form-control restaurant-select"></select>
      </div>
    </div>
    <hr/>
    <div class="col-md-2">
      <ul class="nav nav-pills nav-stacked">
        <li ng-class="{ active: isActive('/admin/overview')}"><a href="#/admin/overview">Overview</a></li>
        <li ng-class="{ active: isActive('/admin/generators')}"><a href="#/admin/generators">Generators</a></li>
      </ul>
    </div>
    <div class="col-md-10">
      <div ng-include="'views/partials/admin/overview.html'" ng-show="isActive('/admin/overview')"></div>
      <div ng-include="'views/partials/admin/generators.html'" ng-show="isActive('/admin/generators')"></div>
    </div>
  </body>
</html>

And the only js that matters is this:

 $scope.isActive = function (viewLocation) {
    return viewLocation === $location.path();
  };

And the issue is that when the user selects a tab to change (overview/generators) than the entire page is reloaded. This is bad because I am trying to keep the state of the selected business at the top.

What am I doing wrong? Why is the page reloading without me running a reload command?

  • there isn't enough information here to identify your problem properly. If this is indeed "the only js that matters", then this would appear to be a bug with $location.path(). However, you haven't even listed which angular version you are using here. Besides that, what you are showing here is an anti-pattern anyway; you should be using a router or a state machine like ngRoute or ui-router for this instead. – Claies Oct 24 '16 at 18:23
  • This doesn't provide any valuable information at all. You might want to take a look at ng-view https://docs.angularjs.org/api/ngRoute/directive/ngView – 0_0 Oct 24 '16 at 18:26
  • But none of this explains the page reload... I don't think there is a way JS can trigger that outside of the reload method for $route: docs.angularjs.org/api/ngRoute/service/$route – iamsampsan Oct 24 '16 at 18:43
  • you are right, the comments don't explain the page reload, because you haven't provided enough information. a minimal reproducible example would demonstrate what is happening, and give some sort of chance at debugging. what you have in the question right now doesn't help anyone reproduce your issue and identify what might be happening, so the best we can do is offer guesses, or make suggestions on solutions that we know work. – Claies Oct 24 '16 at 22:48
  • the problem is that my minimal examples don't have the problem, and even though I have cut out a lot of unnecessary files in my problematic project it's still too much for an example – iamsampsan Oct 25 '16 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.