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'].
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'].
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"
});
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 */
}