0

I am hitting a REST endpoint at

www.example.com/resource/id

What is the best way for me to extract id from an angular module controller? I have looked into using $routeProvider

$routeProvider.when('/resource/:id', {}).otherwise(...)

This will only work if I set

$locationProvider.html5mode(true)

If it is not set to true, it always ends up in the otherwise clause when I hit www.example.com/resource/8

How can I get this to work even if I don't set $locationProvider.html5mode to true?

3 Answers 3

1

I think you're looking for $route.current.params, I use angular-ui's ui-router ui-router, in which case you would use $stateParams.

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

Comments

0

use www.example.com#/resource/8 instead www.example.com/resource/8

Comments

0

just replace following code:

 $routeProvider.when('/resource/:id', {}).otherwise(...)

with the:

 $routeProvider.when('resource/:id', {}).otherwise(...)

/resource/:id ths take absolute url pattern. and resource/:id take relative url pattern.

so i think this will help you without setting of html mode true.

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.