0

I have the following routing:

.when('/stories/:action/:assetId', {
  templateUrl: 'sometpl.html',
  controller: 'ctrl'
}

now... how to make it that 'action' can match only specified group of words, for example ['read', 'list'].

2 Answers 2

0

Please see 18131834, which has this answer:

Another way is to use the ui-router which supports regular expressions for route params:

$stateProvider.state("artists-index", {
    url: "/artists/{page:[0-9]*}",
    templateUrl: "/www/artists/index.html",
    controller: "ArtistsIndexController"
});

$stateProvider.state("artists-profile", {
    url: "/artists/{name}",
    templateUrl: "/www/artists/profile.html",
    controller: "ArtistsProfileController"
});
Sign up to request clarification or add additional context in comments.

Comments

0

You can do this: In the controller you get the action and store into a varibale ( I supose you already did that ), then you check if that variable is in an array of strings (supported actions). Like:

String action = 'read'; // Action from url
String supportedActions = ['read', 'list']
boolean contains = false;
for (String item : supportedActions) {
    if (action.equalsIgnoreCase(item)) {
       contains = true;
       switch(action){
           case 'read':{
               /* Do your magic */
           }
           case 'list':{
               /* Do more magic */
           }
       }
    } 
}
if(!contains){
    /* I don't know that action */
}

Comments

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.