1

What I am trying to achieve here is the following. I want to create a state Url with just a "/" that will get called no matter what route we are on. currently not working, am sure I am missing something not sure what exactly. if someone can help I would appreciate

defineState('main', {
            url: "/",
            controller: function () {
                console.log();
            },
        });
r0m4n
  • 3,474
  • 3
  • 34
  • 43
Serge
  • 33
  • 1
  • 6

2 Answers2

1

Are you using ng-route or ui-router?

with ui-router you can dot this

state('home', {
        url: '/',
        templateUrl: 'home.html'
    });
adrianolsk
  • 332
  • 1
  • 11
  • ui-router. The thing is I dont really have a templateUrl. So I need one. I would really like to have that route called everytime I changed the route – Serge May 04 '16 at 21:46
  • You don't need template, you can use states with '$urlRouterProvider.otherwise("/")', I will change my sample. – gevorg May 04 '16 at 21:51
0

Look following answer How to watch for a route change in AngularJS?:

$scope.$on('$routeChangeStart', function(next, current) { 
   ... you could trigger something here ...
});
Community
  • 1
  • 1
gevorg
  • 4,835
  • 4
  • 35
  • 52
  • this works but not when I switch route. ie : /users . I need a route that is called every time I change views – Serge May 04 '16 at 22:58
  • If you don't have state with '/users' url it should work. – gevorg May 04 '16 at 22:59
  • If you need to execute something on view change you can listen for route change event, I will update answer. – gevorg May 04 '16 at 23:04