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();
            },
        });

2 Answers 2

1

Are you using ng-route or ui-router?

with ui-router you can dot this

state('home', {
        url: '/',
        templateUrl: 'home.html'
    });
Sign up to request clarification or add additional context in comments.

2 Comments

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
You don't need template, you can use states with '$urlRouterProvider.otherwise("/")', I will change my sample.
0

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

$scope.$on('$routeChangeStart', function(next, current) { 
   ... you could trigger something here ...
});

3 Comments

this works but not when I switch route. ie : /users . I need a route that is called every time I change views
If you don't have state with '/users' url it should work.
If you need to execute something on view change you can listen for route change event, I will update answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.