0

What i am trying to implement:

param value should be one of a,b,c,d,e. If the param value is not in the given list of values, user should be redirected.

This implementation is giving me "Infinite $digest Loop" error. How can i make this work?

$routeProvider
        .when("/:param", {
            templateUrl: function(params){
                if($.inArray(params.param, ["a","b","c","d","e"]) > -1)
                    return "templates/index.html";
                else
                    location.replace("#/a");
            },
            controller: 'F'
        })

1 Answer 1

1

Instead of doing it in your route configuration, you could try and do it in your controller. The following code assumes that provided route parameters are ?a=value&b=value:

app.controller('MyController', function ($scope, $location) {
    var currentParams = $location.search(); // { a: 'value', b: 'value' }

    // if all required params are not present, use `$location.replace`
});
Sign up to request clarification or add additional context in comments.

1 Comment

Looks like the way to go. However i will keep this question open for now for other suggestions as well. Thanks for helping. :)

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.