user2901304
user2901304

Reputation: 713

Angular ng-if specific route

Is there a way to show a div if view is a certain route. I have a universal header and footer but there is one thing on the header I don't want to show on my / route.

<body>     
  <header>
  <section ng-if=""></section>
  </header>

  <div ng-view class="view">

  <footer></footer>
</body>

Upvotes: 1

Views: 2738

Answers (1)

Brian Lewis
Brian Lewis

Reputation: 5729

You could leverage $routeChangeSuccess. Something like this should work (not tested):

app.run(function($rootScope, $location) {
  $rootScope.$on('$routeChangeSuccess', function() {
      $rootScope.showSection = $location.path() !== "/";
  });
});

and then...

<body>     
  <header>
  <section ng-if="showSection"></section>
  </header>

  <div ng-view class="view">

  <footer></footer>
</body>

Upvotes: 2

Related Questions