2

I'm trying to replace multiple parameter using angular replace function but the problem that the function detected the first parameter.

eg: I have this route admin/management/{type}/card/{id}, the route.replace function result admin/management/waiting/%7Bid%7D it work fine with the first parameter.

/**
 * @param route 
 * @param obj 
 * @returns 
 */
  getFormattedRouter(route: String, obj: any) {
    console.log(route);//admin/management/{type}/card/{id}
    return route.replace(/{([a-zA-Z_]+?)}/, function (match, capture) {
      console.log(match);//{type}
      console.log(capture);//waiting
      //detected the first one then stops
      return obj[capture];
      //admin/management/waiting/%7Bid%7D
    });
  }

how can I detect all the parameters in a route.

1 Answer 1

3

Your regexp does not seem to be capturing all the matches, you can try this instead /({\w*})/g. Note also the g at the end that indicates the fact that you want to find all the matches, not stop after the first one. Check this link for more info.

Sign up to request clarification or add additional context in comments.

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.