0

I'm using ngRoute from AngularJS.

I have the following code:

(...)
    $routeProvider
        .when('/some-page', {
            templateUrl: 'some-page.html',
            controller: 'SomeController'
        })
(...)

And i want to open /some-page if a condition (e.g. $scope.isOpenned) is true. Otherwise, it should redirect to /other-route

Christopher
  • 3,379
  • 7
  • 25
  • 36
  • This isn't going to work the way you want using `$routeprovider`, since routes are processed before controllers are available (and thus, before `$scope.isOpened` would be). You would need to control this at the HTML level, or at the controller level. – Claies Aug 24 '15 at 00:48

1 Answers1

0

What about something like this?

<div>
 <a ng-hide="!yourBool" href="#/some-page">Link if True</a>
 <a ng-hide="yourBool" href="#/other-route">Link if False</a>
</div>

<script src="vendors/angular.min.js"></script>
<script>
 angular.module('app', [])

 .controller('AppCtrl', ['$scope', function($scope) {

  $scope.yourBool = false;

 }]);
</script>
SuperVeetz
  • 2,128
  • 3
  • 24
  • 37